Breakout Strategy help with my code

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #31048 quote
    Abz
    Participant
    Veteran

    Hello

    looking for some help on the strategy below.

    1. upper is the highest price between 080000 and 090000
    2. enter short when price goes under “upper” but only if next bar closes under upper and high on this bar must also be below upper
    3.  SL shoud be the amount of points between upper and lower in the timeframe 080000 – 090000
    4. profitt target shoud be lower from the time frame 080000 – 090000
    5. same goes for Long
    6. enter long when price goes under lower and next bar closes above lower and lowest of this bar is also above lowest.
    7. SL shoud be the amount of points between upper and lower in the timeframe 080000 – 090000
    8. profitt target shoud be upper from the time frame 080000 – 090000
    DEFPARAM CumulateOrders = false // Cumulating positions
    DEFPARAM PRELOADBARS = 1000
    DEFPARAM FLATAFTER = 220000
    
    IF Time = 080000 THEN
    TradeCounter = 0
    ENDIF
    
    // Trading Hours
    IF (Time >= 090000 AND Time <= t1) and dayofweek<=5 then// or (Time >= 220000 AND Time <= 220100) and dayofweek=1  THEN //
    Tradetime=1
    else
    Tradetime=0
    endif
    t1=220000
    
    //Settings
    once upper=0
    once lower=0
    
    // calculate upper and lower
    endtime = 090000
    If Time = endtime then
    upper=highest[12](high)
    lower=lowest[12](low)
    dif=round(abs((lower-upper)*pipsize*pointvalue))
    endif
    
    //looking for short position
    entershort1 = close[1] > upper
    entershort2 = close crosses under upper
    entershort3 = close < upper
    
    if not onmarket and entershort1 and entershort2 and entershort3 then
    fadeshort=1
    elsif onmarket then
    fadeshort=0
    endif
    
    if not onmarket and tradecounter < 1 and tradetime and fadeshort then
    sellshort 5 contracts at market
    TradeCounter = TradeCounter + 1
    endif
    
    set stop loss dif
    set target profit lower
    #31075 quote
    Nicolas
    Keymaster
    Master

    Hi Abz, your code seems a bit “scrambled”, I think you did a lot of debugging and copy/paste 🙂

    I changed a bit some of the lines and added some variables too (still only short position):

    DEFPARAM CumulateOrders = false // Cumulating positions
    DEFPARAM PRELOADBARS = 1000
    DEFPARAM FLATAFTER = 220000
    
    IF Time = 080000 THEN
    TradeCounter = 0
    ENDIF
    
    // Trading Hours
    t1=220000
    tradetime=Time >= 090000 AND Time <= t1 and dayofweek<=5 
    
    // calculate upper and lower
    endtime = 090000
    If Time = endtime then
    upper=highest[12](high)
    lower=lowest[12](low)
    dif=upper-lower
    endif
    
    //looking for short position
    entershort= close[1] crosses under upper and high<upper and close<upper
    
    if not onmarket and tradecounter < 1 and tradetime and entershort then
    sellshort 5 contracts at market
    tp = close-lower
    TradeCounter = TradeCounter + 1
    endif
    
    set stop loss dif
    set target profit tp

    Please consider that I did not test this code, please do your own tests, thank you.

    #31165 quote
    Abz
    Participant
    Veteran

    Thanks Nicolas the code looks much better 🙂

    for long will this work? i tried it and i dont get the entry points i am looking for.

     

    //looking for Long position
    enterlong= close[1] crosses over lower and low>lower and close>lower
    
    if not onmarket and tradecounter < 1 and tradetime and enterlong then
    buy 5 contracts at market
    tp = close-upper
    TradeCounter = TradeCounter + 1
    endif
    #31303 quote
    Abz
    Participant
    Veteran

    hello

    i am testing the strategy with short positions and i see that there are many trades that are executed that does not fulfill the criterias in the code see attached screen. any idea why?

    test.jpg test.jpg
    #31326 quote
    Nicolas
    Keymaster
    Master

    Your upper and lower levels, are they correctly calculated? Did you GRAPH these variables in ProBacktest to see if they are ok?

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Breakout Strategy help with my code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Abz @abbas_sadiq Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Nicolas
8 years, 11 months ago.

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