Backtest – Exit Criteria – Setup bar and Trigger price

Optuma Forums Optuma Scripting Backtest – Exit Criteria – Setup bar and Trigger price

This topic contains 6 replies, has 3 voices, and was last updated by Avatar Trevor R 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #51699
    Avatar
    Joao
    • Topics: 2
    • Replies: 2
    • Posts: 4

    Hi,

    Can you please help with the following requirement in exit criteria in back tester:

     

    Setup bar: Close below a Moving Average:

    Trigger/Exit Price: Price crosses below the low of setup bar

    In attach the exit setup

    Thanks

     

    Joao Rei

     

     

     

     

    Attachments:
    #51707
    Avatar
    Trevor R
    • Topics: 32
    • Replies: 106
    • Posts: 138

    Hi Joao,

    A simple script like the following (based on a 50 Bar Exponential Moving Average using the Close) will meet your basic criteria:

    EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

    Setup = CLOSE(0) < EMA50;

    Setup

    Using SHOWBAR, this will produce the following result:

    20190316 Joao's Script 1

     

    That highlights every Close below the EMA, which may not be quite what you want. A further criteria may be that the previous Close must be above the EMA. The following scripts adds that refinement and results in the chart below.

    EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

    Setup = If(CLOSE(1) > EMA50 AND CLOSE(0) < EMA50,1,0);

    Setup

    20190316 Joao's Script 2

    I hope this helps you find the results you are looking for.

    Cheers

    Trevor

    The Auld Tyma at

    Auld Tyma Data Logo with URL 1 cm

     

    #51943
    Avatar
    Joao
    • Topics: 2
    • Replies: 2
    • Posts: 4

    Thank you Trevor,

    The second code is near of what I need.

    However, to trigger the setup, I need also  the Low of close(0) bar and the Low of close(1) bar to be surpassed on the downside. 

    Any ideas?

     

    Thanks.

     

    #51955
    Avatar
    Trevor R
    • Topics: 32
    • Replies: 106
    • Posts: 138

    Hi Joao,

    I’m not 100% sure I got your extra criteria straight, so here are two options:

    Option 1 (Script: //Ticket #51943 20190324) which requires the Entry Bar to meet:

    • Close of Entry bar and the Close preceding bar to be below to 50 EMA
    • Low of the Entry Bar to be below the Low of the preceding two Bars, regardless of the relationship of the Lows of those two preceding Bars

    This script meets those criteria:

    // Ticket #51943 20190324

    EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

    Sig1 = If(CLOSE(1) > EMA50 AND CLOSE(0) < EMA50, 1, 0);

    Sig2 = If( LOW(0) < LOW(1) and LOW(0) < Low (2), 1, 0);

    Entry = If(Sig1 and Sig2, 1, 0);

    Entry

    The SHOWBAR result from this script is shown in Red on the chart below.

    Option 2 (Script: //Ticket #51943 20190324-A) which requires the Entry Bar to meet:

    • Close of Entry bar and the Close preceding bar to be below to 50 EMA
    • Low of the Entry Bar to be below the Low of the preceding Bar and the Low of the preceding Bar to be below the Low of the Bar preceding it

    This script meets those criteria:

    // Ticket #51943 20190324-A

    EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

    Sig1 = If(CLOSE(1) > EMA50 AND CLOSE(0) < EMA50, 1, 0);

    Sig2 = If( LOW(0) < LOW(1) and LOW(1) < Low (2), 1, 0);

    Entry = If(Sig1 and Sig2, 1, 0);

    Entry

    The SHOWBAR result from this script is shown in Blue on the chart below.

    20190324 Joao's Script 3

    Cheers

    Trevor

    The Auld Tyma at

    Auld Tyma Data Logo with URL 1 cm

    #51963
    Avatar
    Joao
    • Topics: 2
    • Replies: 2
    • Posts: 4

    Hi Trevor,

    Thank you very much for your help.

    These 2 options follow the requirements.

    Best Regards

    Joao

     

     

     

    #51967
    Avatar
    Steve
    • Topics: 9
    • Replies: 19
    • Posts: 28

    Hi

    I’m looking for something similar to this in the backtester.

    I am able to create a script that gives me a setup bar. Instead of entering on the next open, or the close of the signal day, I would prefer to enter as soon as the next bar breaks the high of the setup bar (for long entry). And if that next bar fails to break the high, I would like to delete the pending trade.

    Is it possible to simulate this through the backtester?

    Thanks
    Steve

     

    #51983
    Avatar
    Trevor R
    • Topics: 32
    • Replies: 106
    • Posts: 138

    Hi Steve,

    Please post you code so we can see exactly what you are trying to achieve and so provide contextual assistance.

    Cheers

    Trevor

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close