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.
All the best
From the Optuma Knowledge Base,
there is mention of the Min Hold Days and Max Hold Days, although the screenshot below shows only Min Hold Days.
However, the Backtester dialog box I have doesn’t seem to show either Min Hold Days or Max Hold Days. (Screenshot below.)
Am I missing something?
Thanks Ian. Those min/max hold day options are only available with a Professional or Enterprise Services subscription, and not with Trader Services.
As such, your exit script can be defined as follows for 5 days after the entry:
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:
I tested that and got what seemed to be correct results.
I used as the entry criteria:
And as the exit criteria:
If I want to include extra entry criteria such as volume, would that just go in the Entry Criteria section?
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.
But if after trigger and subsequent entry if any trigger comes backtester start taking measurement from that next signal.
Here is the example i have set exit as 252 days from entry what backtester is taking is latest signal rather than entry point.
While scanning saw this post also where you suggested to use offset function even that also have issues.
Here is the example i put exit as 252 bars offset but exit happens only after 27 bars because there was a signal 252 days before.
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.