Script (for Backtester) to Exit After x No. of Days

Optuma Forums Optuma Scripting Script (for Backtester) to Exit After x No. of Days

Tagged: 

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #58855
    Ian
    • Topics: 6
    • Replies: 7
    • Posts: 13

    Hi,

    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:

    (Entry Criteria)

    #58857
    Mathew
    • Topics: 41
    • Replies: 2,047
    • Posts: 2,088

    Hi Ian,

    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

    Mathew

    #58871
    Ian
    • Topics: 6
    • Replies: 7
    • Posts: 13

    Thanks Mathew,

    From the Optuma Knowledge Base,

    https://help.optuma.com/kb/faq.php?id=735

    there is mention of the Min Hold Days and Max Hold Days, although the screenshot below shows only Min Hold Days.

    BackTester_KB

    However, the Backtester dialog box I have doesn’t seem to show either Min Hold Days or Max Hold Days. (Screenshot below.)

    BackTester_IJ.JPG

    Am I missing something?

    #58873
    Darren
    • Topics: 76
    • Replies: 1,059
    • Posts: 1,135

    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:

    Capture

    #58891
    Ian
    • Topics: 6
    • Replies: 7
    • Posts: 13

    Thanks Darren.

    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?

     

    #58897
    Darren
    • Topics: 76
    • Replies: 1,059
    • Posts: 1,135

    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.

    #71767
    Deepak
    • Topics: 95
    • Replies: 88
    • Posts: 183

    Hii Sir,

    But if after trigger and subsequent entry if any trigger comes backtester start taking measurement from that next signal.

    #71769
    Deepak
    • Topics: 95
    • Replies: 88
    • Posts: 183

    Time since signal exit

    Here is the example  i have set exit as 252 days from entry what backtester is taking is latest signal rather than entry point.

    #71771
    Deepak
    • Topics: 95
    • Replies: 88
    • Posts: 183

    While scanning saw this post also where you suggested to use offset function even that also have issues.

    max hold days script

    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.

    Offset Funtion

    #71851
    Kim
    • Topics: 22
    • Replies: 29
    • Posts: 51

    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:

    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:

    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.

    #71853
    Mathew
    • Topics: 41
    • Replies: 2,047
    • Posts: 2,088

    Hi Kim,

    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.

    1 user thanked author for this post.
    Kim
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest