I would like to backtest some candlestick patterns, with an exit after a certain number of days, eg. 3, 4 or 5 days.
I’ve tried the TIMESINCESIGNAL function for the exit, but when checking the Trade List produced, the exits seem to be on the next trading day. Either I’ve got the Test Rule parameters wrong in the Backtester, or the script wrong. This is the Exit Criteria script I tried:
In the properties of the Backtester there is an option called “Max Hold Time” just change that to the number of days you want to hold for. Then you do not need an exit script.
If you plan on doing lots of these types of tests then the Signal Testing add-on module may be an option for you. Click here for more info (including videos).
As an example, here’s the Bullish Engulfing signal test results for the 71 SPX events over the last 10 years, looking 5 days before and 22 days after each occurrence:
Correct - just add the extra filters to the last line of the entry criteria, such as ‘and VOL()>100000’ for volume, or ‘and CLOSE()>1’ for a price-based filter.
I’ve had the same problem with my exit script too. In certain conditions, my entry script may generate 2-3 signals within a 2 week period. I’d like to be able to test various time-based exits, but it’s not possible. Even if “Max Hold Time” was available in Trader Services, it wouldn’t be enough to do tests such as:
v1 = EntryCriteria;
TIMESINCESIGNAL(v1) > 30 and PRICEATSIGNAL(v1) < CLOSE()
I’ve tried using NOREPEAT, but as I can’t know when or how often the entry signal will occur in the future, it’s really just a shot in the dark.
The backtester itself only takes the first signal when calculating results, so I don’t understand why it’s not possible to make that visible to the scripting language. I’m thinking a new “BACKTESTSIGNAL” option would solve the problem. Obviously enough such a condition wouldn’t do anything if selected on a chart. So:
v1 = EntryCriteria;
TIMESINCESIGNAL(v1,BACKTESTSIGNAL=True) > 30 and PRICEATSIGNAL(v1,BACKTESTSIGNAL=True) < CLOSE()
FYI, I raised this a few years ago at https://forum.optuma.com/topic/back-test-results-2/. Mathew suggested he was going to have a look at it. I’ve been in software development and understand how “low priority” requests often get lost in the ocean of “things to do”.
I’m sure lots of people would benefit from this feature.
Quick Answer: Nothing will be done in the short term.
Longer Answer: The current back tester works by running scans for all the Entry Signals and Exit Signals. Then is sorts them all together by date. Then we start processing “signals” based on available capital and holdings. There is no mechanism to do a calculation after a signal is entered.
It’s not the way that I am building the new Quant Engine, but to change it is way too much in costs and times when the new one should be finished within the next few months. The new engine is also why I am saying “no” to virtually every request. We’ve had way too many distractions take us away from this development and I’m determined to have it fully released by next year. We don’t have the resources to do both developments in parallel so all our focus is on the new engine now.
I’ve finished building in a new Stop System into the new web based version of Optuma. In that I am including a Time based Stop and it will be aware of the possibility of multiple buy on different days but only the first will exit when the time stop is hit.