September 12, 2019 at 8:58 am #54637Chad
- Topics: 4
- Replies: 13
- Posts: 17
Hello, I am trying to create a sell script that does what the max hold days function in the backtester does. I would like to use it as part of an “or” function as a sell criteria. What’s the best way to do this? Do I need to put the buy criteria in the code in order to get a TimeSinceSignal?
For instance I would like to simply have a “sell 30 days from entry” option.
Thanks.September 12, 2019 at 11:18 am #54639Trevor R
- Topics: 101
- Replies: 304
- Posts: 405
Hi Chad and Others using this Forum
When seeking assistance on a script, please help yourself and those of us that are inclined to respond by ALWAYS posting your attempt at the script. Include in your script comments describing what the follow line(s) of code is a attempting to achieve. The more comments the better. That way we have a chance of understanding exactly what it is you are trying to achieve, and you, and others, will learn by the advice subsequently provided. Also, your attempt may only need minor changes and so engenders a more speedy response (like one I addressed the other day that only need commas in numbers changed to periods). The more detail provided as to what you are trying to do makes is much easier to provide assistance, so also include, when possible, a chart annotated with appropriate comments that shows the undesired outcome of your unsuccessful attempt at scripting.
Note, I am not an employee of Optuma, but one who is willing to assist those that demonstrate that they have tried something and are not just asking for some-one else to do all the work in creating the script desired.
TrevorSeptember 12, 2019 at 7:05 pm #54643Darren
- Topics: 66
- Replies: 618
- Posts: 684
As an Enterprise Services client you have access to the quantitative Signal Tester which will allow you to set the Periods After to 30. This will calculate the average performance and statistics 30 days after each signal without the need for an exit, as per this example (tip: drag the vertical yellow line in the results to the left to see the results before the 30 days):
September 13, 2019 at 3:51 am #54649Chad
- This reply was modified 1 year ago by Darren.
- Topics: 4
- Replies: 13
- Posts: 17
Hey Darren, thanks, but I think my question was misunderstood. I am looking to write my own script to find the number of days in a trade so that I can then use it as an “or” function in the backtester sell script top exit rather than the “N max hold days” option provided (see screen shot).
If you use the max hold day function in the backtester it will always sell after 30 days. I do not want this, but I want it as an option. I want to run a script that will sell based on my 1. “other sell criteria” “or” 2. a “30/60/90/120/n # of holding days” but do not know how to best go about the n # of holding days script.
Is the correct way to do this to use TimeSinceSignal or is there a better command?
I looked over the entire list of commands and couldn’t find one for DaysInTrade or something similar. ThanksSeptember 13, 2019 at 8:28 am #54655Matthew
- Topics: 5
- Replies: 367
- Posts: 372
There’s two ways to do this, which is best will depend on your preference. The TimeSinceSignal() function is one way, however if your entry script occurs again within the max time count you’ve set, the count will reset. If your entry criteria triggers often enough it’s possible you may never exit out.
The other option is to use the Offset() function. You can wrap it around your entry script and adjust the offset to the max days you want. This will trigger 30/60/90 days after an entry criteria has triggered, even if another entry occurs within that time.
Here’s a quick example using Close CrossingAbove 150SMA as the entry script so you can see how the two work:
Green = Entry Criteria, Red = Max Day Exit
The two scripts in the above example:
Time Since Signal Example1234567V1 = CLOSE() CrossesAbove MA(BARS=150) ;V2 = TIMESINCESIGNAL(V1) == 30;Plot1 = V1 ;Plot2 = V2 ;plot2.Colour = Red;
Offset Example1234567V1 = CLOSE() CrossesAbove MA(BARS=150) ;V2 = OFFSET(V1, OFFSET=30);Plot1 = V1 ;Plot2 = V2 ;plot2.Colour = Red;
- You must be logged in to reply to this topic.