help coding breakout strategy

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #166368 quote
    ullle73
    Participant
    Senior

    hi

     

    I need help coding a strategy ive been backtesting manually and forwardtested for a while now. Results look promising.

     

    rules:

    • from todays open (midnight) to US open, (15:30 my time gmt +2) creates a rangebox
    • if ADR is below 50%, put sell/buy stop orders 10 pips below/above rangebox
    • target 50 pips, SL 100 pips, breakeven SL after 25 pips
    • if ADR is above 50% no trades
    Boris thanked this post
    #166391 quote
    robertogozzi
    Moderator
    Master

    What ADR is the one you are referencing?:

    • Advance/Decline Ratio
    • Average Daily Range  calculated on Highs & Lows
    • Average Daily Range calculated on Range (pips)

    Do you have any link to that indicator?  PRT have ADX, ADXR, but no ADR.

    #166449 quote
    ullle73
    Participant
    Senior

    average daily range in pips. Could be one thats based on similar calculation in prt 🙂 thanks!

    #166523 quote
    robertogozzi
    Moderator
    Master

    Try this:

    DEFPARAM CumulateOrders = FALSE
    IF Not OnMarket THEN
       MyExit = 0
    ELSE
       c1 = 0
    ENDIF
    // ADR Average Daily Range
    MyADR       = average[300,0](range)
    //
    IF Time = 000000 THEN
       MyHI     = high
       MyLO     = low
       c1       = 0
    ENDIF
    IF Time <= 153000 THEN
       MyHI     = max(MyHI,high)
       MyLO     = min(MyLO,low)
       MyRange  = MyHI - MyLO
       c1       = ((MyRange / MyADR) * 100) < 50
    ENDIF
    IF Time >= 153000 AND c1 THEN
       BUY       1 Contract AT MyHI + 10 * pipsize STOP
       SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
       SET TARGET pPROFIT 50
       SET STOP   pLOSS   100
    ENDIF
    IF MyExit = 0 THEN
       IF (LongOnMarket AND (close - TradePrice) >= 25 * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= 25 * pipsize) THEN
          MyExit = TradePrice
       ENDIF
    ENDIF
    IF MyExit > 0 THEN
       SELL      AT MyExit STOP
       EXITSHORT AT MyExit STOP
    ENDIF
    //GraphOnPrice TradePrice coloured(0,0,255,255)
    //GraphOnPrice MyHI       coloured(0,128,0,200)
    //GraphOnPrice MyLO       coloured(255,0,0,255)
    //Graph close - TradePrice
    //Graph c1
    //Graph MyADR
    //Graph MyRange
    jamesfx thanked this post
    #166530 quote
    GraHal
    Participant
    Master

    Should Line 15 read as below?

    IF Time >= 153000 THEN //not <
    #166546 quote
    robertogozzi
    Moderator
    Master

    No, those two values must be updated earlier or on that time.

    After that time the range is defined and trades can be entered.

    GraHal thanked this post
    #166836 quote
    ullle73
    Participant
    Senior

    it does not take any trades at all? tested with 100k bars on 1 min, 5 min, 30 min

    #166845 quote
    robertogozzi
    Moderator
    Master

    Try this one. I changed the average with yesterday’s range:

    DEFPARAM CumulateOrders = FALSE
    IF Not OnMarket THEN
    MyExit = 0
    ELSE
    c1 = 0
    ENDIF
    // ADR Average Daily Range
    MyADR       = average[20,0](Dhigh(1) - Dlow(1))
    //
    IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
    MyHI     = high
    MyLO     = low
    c1       = 0
    ENDIF
    IF Time <= 153000 THEN
    MyHI     = max(MyHI,high)
    MyLO     = min(MyLO,low)
    MyRange  = MyHI - MyLO
    c1       = ((MyRange / MyADR) * 100) < 50
    ENDIF
    IF Time >= 153000 AND c1 THEN
    BUY       1 Contract AT MyHI + 10 * pipsize STOP
    SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
    SET TARGET pPROFIT 50
    SET STOP   pLOSS   100
    ENDIF
    IF MyExit = 0 THEN
    IF (LongOnMarket AND (close - TradePrice) >= 25 * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= 25 * pipsize) THEN
    MyExit = TradePrice
    ENDIF
    ENDIF
    IF MyExit > 0 THEN
    SELL      AT MyExit STOP
    EXITSHORT AT MyExit STOP
    ENDIF
    //GraphOnPrice TradePrice coloured(0,0,255,255)
    //GraphOnPrice MyHI       coloured(0,128,0,200)
    //GraphOnPrice MyLO       coloured(255,0,0,255)
    //Graph close - TradePrice
    //Graph c1
    //Graph MyADR
    //Graph MyRange
    ullle73 thanked this post
    #166914 quote
    ullle73
    Participant
    Senior

    perfect! thanks alot roberto!! 😀

    robertogozzi thanked this post
    #191599 quote
    ullle73
    Participant
    Senior

    Roberto, could you possibly devide this code into one SL,TP and BE-stop for long and one for short? Want to try to optimze code for both long and short 😀

    #191623 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM CumulateOrders = FALSE
    IF Not OnMarket THEN
    MyExit = 0
    ELSE
    c1 = 0
    ENDIF
    // ADR Average Daily Range
    MyADR       = average[20,0](Dhigh(1) - Dlow(1))
    //
    IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
    MyHI     = high
    MyLO     = low
    c1       = 0
    ENDIF
    IF Time <= 153000 THEN
    MyHI     = max(MyHI,high)
    MyLO     = min(MyLO,low)
    MyRange  = MyHI - MyLO
    c1       = ((MyRange / MyADR) * 100) < 50
    ENDIF
    IF LongOnMarket THEN
    SET TARGET pPROFIT 50          //you can change this value for LONG trades
    SET STOP   pLOSS   100         //you can change this value for LONG trades
    ELSIF ShortOnMarket THEN
    SET TARGET pPROFIT 50          //you can change this value for SHORT trades
    SET STOP   pLOSS   100         //you can change this value for SHORT trades
    ENDIF
    IF Time >= 153000 AND c1 AND Not OnMarket THEN
    BUY       1 Contract AT MyHI + 10 * pipsize STOP
    SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
    SET TARGET pPROFIT 50     //initial values cannot be different with pending orders
    SET STOP   pLOSS   100
    ENDIF
    IF MyExit = 0 THEN
    IF LongOnMarket AND (close - TradePrice) >= 25 * pipsize THEN    //you can change this value for LONG trades
    MyExit = TradePrice
    ENDIF
    IF ShortOnMarket AND (TradePrice - close) >= 25 * pipsize THEN   //you can change this value for SHORT trades
    MyExit = TradePrice
    ENDIF
    ENDIF
    IF MyExit > 0 THEN
    IF LongOnMarket THEN
    SELL      AT MyExit STOP
    ELSIF ShortOnMarket THEN
    EXITSHORT AT MyExit STOP
    ENDIF
    ENDIF
    //GraphOnPrice TradePrice coloured(0,0,255,255)
    //GraphOnPrice MyHI       coloured(0,128,0,200)
    //GraphOnPrice MyLO       coloured(255,0,0,255)
    //Graph close - TradePrice
    //Graph c1
    //Graph MyADR
    //Graph MyRange
    ullle73 thanked this post
    #191631 quote
    ullle73
    Participant
    Senior

    wow, perfect 😀 thanks roberto!!!

    one more quick question,

    • could you add line to not take a position after certain time, example at 10 aclock
    • and a line for maximum numbers of trades per day
    #191639 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM CumulateOrders = FALSE
    ONCE MaxTrades = 2                     //no more than 2 trades a day
    ONCE Tally     = 0
    IF IntraDayBarIndex = 0 THEN
    Tally = 0
    ENDIF
    IF Not OnMarket THEN
    MyExit = 0
    ELSE
    c1 = 0
    ENDIF
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR ((Not OnMarket AND Not OnMarket[1]) AND (StrategyProfit <> StrategyProfit[1]))
    IF NewTrade THEN
    Tally = Tally + 1
    ENDIF
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // ADR Average Daily Range
    MyADR       = average[20,0](Dhigh(1) - Dlow(1))
    //
    IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
    MyHI     = high
    MyLO     = low
    c1       = 0
    ENDIF
    IF Time <= 153000 THEN
    MyHI     = max(MyHI,high)
    MyLO     = min(MyLO,low)
    MyRange  = MyHI - MyLO
    c1       = ((MyRange / MyADR) * 100) < 50
    ENDIF
    IF LongOnMarket THEN
    SET TARGET pPROFIT 50          //you can change this value for LONG trades
    SET STOP   pLOSS   100         //you can change this value for LONG trades
    ELSIF ShortOnMarket THEN
    SET TARGET pPROFIT 50          //you can change this value for SHORT trades
    SET STOP   pLOSS   100         //you can change this value for SHORT trades
    ENDIF
    IF Time >= 153000 AND Time <= 180000 AND c1 AND Tally < MaxTrades AND Not OnMarket THEN   //trade only between 15:30 and 18:00
    BUY       1 Contract AT MyHI + 10 * pipsize STOP
    SELLSHORT 1 Contract AT MyLO - 10 * pipsize STOP
    SET TARGET pPROFIT 50     //initial values cannot be different with pending orders
    SET STOP   pLOSS   100
    ENDIF
    IF MyExit = 0 THEN
    IF LongOnMarket AND (close - TradePrice) >= 25 * pipsize THEN    //you can change this value for LONG trades
    MyExit = TradePrice
    ENDIF
    IF ShortOnMarket AND (TradePrice - close) >= 25 * pipsize THEN   //you can change this value for SHORT trades
    MyExit = TradePrice
    ENDIF
    ENDIF
    IF MyExit > 0 THEN
    IF LongOnMarket THEN
    SELL      AT MyExit STOP
    ELSIF ShortOnMarket THEN
    EXITSHORT AT MyExit STOP
    ENDIF
    ENDIF
    //GraphOnPrice TradePrice coloured(0,0,255,255)
    //GraphOnPrice MyHI       coloured(0,128,0,200)
    //GraphOnPrice MyLO       coloured(255,0,0,255)
    //Graph close - TradePrice
    //Graph c1
    //Graph MyADR
    //Graph MyRange
    #191810 quote
    ullle73
    Participant
    Senior

    i love you roberto!! thanks! 😀

    #193737 quote
    ullle73
    Participant
    Senior

    Roberto, i ended up using this version. But system is not taking any positions last 18 days. But it should, could you take a look at what might be wrong?

     

    //-------------------------------------------------------------------------
    // Main code : ryd range box 1-2 min US30 DOW
    //-------------------------------------------------------------------------
    
    
    
    
    DEFPARAM CumulateOrders = FALSE
    ONCE PL = 130.0
    ONCE SL = 60.0
    ONCE t = 50.0
    ONCE tS = 50.0
    ONCE x = 40.0
    ONCE y = 1.0
    IF Not OnMarket THEN
    MyExit = 0
    ELSE
    c1 = 0
    ENDIF
    // ADR Average Daily Range
    MyADR = average[20,0](Dhigh(1) - Dlow(1))
    //
    IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THEN
    MyHI = high
    MyLO = low
    c1 = 0
    ENDIF
    IF Time <= 142900 THEN
    MyHI = max(MyHI,high)
    MyLO = min(MyLO,low)
    MyRange = MyHI - MyLO
    c1 = ((MyRange / MyADR) * 100) < x //75
    ENDIF
    IF Time >= 142900 AND c1 THEN
    BUY 0.2 Contract AT MyHI + y * pipsize STOP
    SELLSHORT 0.2 Contract AT MyLO - y * pipsize STOP
    SET TARGET pPROFIT PL //40
    SET STOP pLOSS SL //80
    ENDIF
    IF MyExit = 0 THEN
    IF (LongOnMarket AND (close - TradePrice) >= t * pipsize) OR (ShortOnMarket AND (TradePrice - close) >= tS * pipsize) THEN //27.5 37.5
    MyExit = TradePrice
    ENDIF
    ENDIF
    IF MyExit > 0 THEN
    SELL AT MyExit STOP
    EXITSHORT AT MyExit STOP
    ENDIF
    //GraphOnPrice TradePrice coloured(0,0,255,255)
    //GraphOnPrice MyHI coloured(0,128,0,200)
    //GraphOnPrice MyLO coloured(255,0,0,255)
    //Graph close - TradePrice
    //Graph c1
    //Graph MyADR
    //Graph MyRange
Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.

help coding breakout strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ullle73 @jonas_rydqvist Participant
Summary

This topic contains 19 replies,
has 3 voices, and was last updated by robertogozzi
3 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/07/2021
Status: Active
Attachments: 2 files
Logo Logo
Loading...