Range Breakout 5min

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #24219 quote
    O-jay8
    Participant
    Veteran

    Hello All,
    I am new here and that is my first post. I am going through a lot of blogs and strategies for the last week and I am very impressed by the effort you guys put in this platform. I see you are are very dedicated to find profitable strategies, effective indicators, screeners etc. and help one another.
    Quickly to myself. I have a demo account at IG and do some manual and automatic trading there. I want to test one of my strategies with backtest but due to my limited coding abilities, I stuck at several points. I hope some of you guys can help me.

    Now to a part of my little strategy:
    I want to trade the breakout of a range (usually on a 5min chart).
    Rangetime: 7am-8am UK time (I have already problems to set the range constant, used a method by nicolas but unforunately works only as an indicator)
    Breakout: at toplevel +10% of Range or lowlevel – 10% of range
    Stoploss: Range/2
    Take profit: Range

    The first advice I need is to set the Range constant in the period 7am to 8am without having to call my own little created indicator.
    Second advice I need is, instead of taking profit, do a trailing stop. In case we are Long, set stop on previous low. In case we are short, set stop on previous high.

    Thank you in advance

    Oliver

    // Open Range Breakout DAX 5 Min
    
    ONCE Start = 070000
    ONCE End = 080000
    // trading window
    ONCE BuyTime = 080000
    ONCE SellTime = 163000
    
    // money management
    Capital = 10000
    Risk = 0.01
    equity = Capital + StrategyProfit
    maxrisk = round(equity*Risk)
    Distance=0.1
    PositionSize = abs(round((maxrisk/RR)/PointValue)*pipsize)
    
    // calculate high/low and sl/tp
    if time >= start and time <=end or intradaybarindex =0 then
    DAYSTARTINDEX = INTRADAYBARINDEX
    HIGHLEVEL = HIGHEST[INTRADAYBARINDEX - DAYSTARTINDEX+12](HIGH)
    LOWLEVEL = LOWEST [INTRADAYBARINDEX - DAYSTARTINDEX+12](LOW)
    Area=highlevel-lowlevel
    TP=area-area*distance
    RR=area/2+area*distance
    endif
    // position management
    IF Time >= BuyTime AND Time <= SellTime THEN
    // Long
    IF Not longonmarket and not shortonmarket THEN
    IF close < highlevel and close > lowlevel THEN
    BUY PositionSize CONTRACT AT highlevel+area*distance stop
    ENDIF
    ENDIF
    // short
    IF Not shortonmarket and not longonmarket THEN
    IF close < highlevel and close > lowlevel THEN
    SELLSHORT PositionSize CONTRACT AT lowlevel-area*distance Stop
    ENDIF
    ENDIF
    // close positions
    IF Time = SellTime THEN
    IF LONGONMARKET THEN
    SELL AT MARKET
    ENDIF
    IF SHORTONMARKET AND Time = SellTime THEN
    EXITSHORT AT MARKET
    ENDIF
    endif
    set target profit TP
    set stop loss RR
    ENDIF
    

    Sorry for my code, I dont know why the syntax colors are not shown.
    Just for your information: here the indicator code I used to set the range top and bottom level.

    start=70000
    end=80000
    
    if time >= start and time <=end or intradaybarindex =0 then
    DAYSTARTINDEX = INTRADAYBARINDEX
    HIGHLEVEL = HIGHEST[INTRADAYBARINDEX - DAYSTARTINDEX+12](HIGH)
    LOWLEVEL = LOWEST [INTRADAYBARINDEX - DAYSTARTINDEX+12](LOW)
    endif
    return highlevel, lowlevel
    #24231 quote
    Nicolas
    Keymaster
    Master

    What is the code of mine you tried to find the highest/lowest values of the range?

    Did you try to GRAPH your variables to see how they were calculated and to find if they are correct?

    There are a lot of nested conditions, I think it could be reduce to less lines, there may be some conditions not correctly tested somewhere.

    #24242 quote
    O-jay8
    Participant
    Veteran

    Hi Nicolas,
    Yes I want to find the highest/lowest in the range.
    I think I managed what I planned to do. But I had to use the function highest high and lowest low for the last 12 bars in a 5min chart.
    I think there is a smarter idea with intradaybarindex, where you can test the strategy throughout all timeframes without changing the code. That is why I tried to use your code unfortunately without success.

    I mangaged to reduce the code as well a bit.

    Here my new code.

    // Open Range Breakout DAX 5 Min
    
    ONCE Start = 070000
    ONCE End = 080000
    // trading window
    ONCE BuyTime = 080000
    ONCE SellTime = 163000
    
    // money management
    //Capital = 10000
    //Risk = 0.01
    //equity = Capital + StrategyProfit
    //maxrisk = round(equity*Risk)
    //PositionSize = abs(round((maxrisk/RR)/PointValue)*pipsize)
    positionsize=1
    Distance=0.1
    // calculate high/low and sl/tp
    if time >= start and time <=end then
    top= highest[12](high)
    bottom= lowest[12](low)
    Area=top-bottom
    TP=area-area*distance
    RR=area/2+area*distance
    endif
    // position management
    IF Time >= BuyTime AND Time <= SellTime THEN
    // Long
    IF Not onmarket and close < top THEN
    BUY PositionSize CONTRACT AT top+area*distance stop
    ENDIF
    // short
    IF Not onmarket and close >bottom THEN
    SELLSHORT PositionSize CONTRACT AT bottom-area*distance Stop
    ENDIF
    set target profit TP
    set stop loss RR
    ENDIF
    #24252 quote
    Nicolas
    Keymaster
    Master

    I modify the code with my own breakout box code, seems to work correctly I think. Please review it.

    // Open Range Breakout DAX 5 Min
    
    ONCE Start = 070000
    ONCE End = 080000
    // trading window
    ONCE BuyTime = 080000
    ONCE SellTime = 163000
    
    positionsize=1
    Distance=0.1
    
    if intradaybarindex=0 then
    top=0
    bottom=close*100
    endif
    
    tcondition = time>Start and time<=End
    
    if tcondition then
    top = max(top,high)
    bottom = min(bottom,low)
    Area=top-bottom
    TP=area-area*distance
    RR=area/2+area*distance
    endif
    
    // position management
    IF Time >= BuyTime AND Time <= SellTime THEN
    // Long
    IF Not onmarket and close < top THEN
    BUY PositionSize CONTRACT AT top+area*distance stop
    ENDIF
    // short
    IF Not onmarket and close >bottom THEN
    SELLSHORT PositionSize CONTRACT AT bottom-area*distance Stop
    ENDIF
    set target profit TP
    set stop loss RR
    ENDIF
    breakout-open-range.png breakout-open-range.png
    #77478 quote
    O-jay8
    Participant
    Veteran

    Hello guys,
    I picked up my old topic as I had some time.
    For the range breakout before the official trading hours I used now a trailing stop approach which got posted once by Nicolas.
    Furthermore I skipped the hours around lunch and included a ADX indicator.

    It looks not as bad as I expected actually.

    If you have time, let me know what you are thinking and whether you have some ideas of improvement.

    Kind regards

    Dax-Breakout-Range-5min.itf Breakout-Dax-5-min.png Breakout-Dax-5-min.png
    #77703 quote
    Nicolas
    Keymaster
    Master

    Thanks a lot for feedback on your strategy. I made my own test and result is attached. Maybe it would benefit from the trailing stop calculated and triggered on a lowest timeframe with the new MTF capabilities.

    dax-breakout-5-minutes-automatic-trading.png dax-breakout-5-minutes-automatic-trading.png
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Range Breakout 5min


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
O-jay8 @o-jay8 Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Nicolas
7 years, 7 months ago.

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