open range strategy code – lot of success

Viewing 15 posts - 1 through 15 (of 39 total)
  • Author
    Posts
  • #48596 quote
    dillongr
    Participant
    Junior

    Hi,

    I have had a lot of success with an open range break strategy and I am trying to see if I can automate the strategy, but my limited knowledge of coding is proving to be a challenge

    I am trying to define the opening range on the 5 min, for a set period of time.  using the dax as an example:

    • open range is high and low of 5 min candles between 8am and close of the 8:55 five min candle.
    • entry is 2nd  5 min close above /below the range
    • exit is a Fibonacci expansion of, 261.8

    very simple and reliable in my intraday trading on SAF40, Dax, Dow, FTSE and US500.

    Does anyone know how you define the range?

    #48614 quote
    Eric
    Participant
    Master

    Hi dillongr

    try something like this for high (hh) you can also use it as an indicator by “return hh” to see that the time are in right place

    starttime = 080000
    endtime = 085959
    
    if intradaybarindex=0 then
    hh = 0
    endif
    
    if time>=starttime and time<=endtime then
    if high>hh then
    hh = high
    endif
    endif
    #48615 quote
    Eric
    Participant
    Master

    and low (ll)

    starttime = 080000
    endtime = 085959
    
    if intradaybarindex=0 then
    ll = 0
    endif
    
    if time>=starttime and time<=endtime then
    if low<ll or ll=0 then
    ll = low
    endif
    endif
    #48618 quote
    Despair
    Blocked
    Master

    Where is your stop loss for this strategy?

    #48620 quote
    dillongr
    Participant
    Junior

    thanks Eric!

    SL is normally at the top or bottom of the range depending if you are long or short.  Price normally comes to test the 50% Fibonacci of the range before continuing on the breakout.  I also use a 15ema to confirm trend direction

    #48621 quote
    Despair
    Blocked
    Master

    If you have a long breakout you take the bottom of the range as SL and for short the top? Sounds funny. I will program this.

    #48622 quote
    Despair
    Blocked
    Master

    Entry condition you write the second close outside the range. Shall this two closes be consecutive?

    And tagte is the 261.8% fibs expansion. So if the range is 100 points wider you have a take profit of 261.8 points above the range top? This is far away!

    #48623 quote
    Despair
    Blocked
    Master

    I coded this here with a profit target at the 161.8% fibo extension (that was already bad enough) and at least for the dax the result was not very promising.

    Here is the code if you want to play with it:

    defparam cumulateorders=false
    
    tradingtime=dayofweek>=1 and dayofweek<=5 and time>=90000
    MA=ExponentialAverage[15](close)
    once tc=0
    
    if time=90000 then
      RangeTop=highest[11](high[1])
      RangeBottom=lowest[11](low[1])
    endif
    
    if intradaybarindex=0 then
      tc=0
    endif
    
    CL=close>RangeTop and close[1]>RangeTop
    CS=close<RangeBottom and close[1]<RangeBottom
    box=RangeTop-RangeBottom
    
    if not onmarket and not tc and tradingtime then
      if CL and close>MA then
        buy 1 contract at market
        tc=1
      elsif CS and close>MA then
        sellshort 1 contract at market
        tc=1
      endif
      set target pprofit box*1.618
    endif
    
    if longonmarket then
      sell at RangeBottom stop
    elsif shortonmarket then
      exitshort at RangeTop stop
    endif
    
    GraHal thanked this post
    #48644 quote
    Andyswede
    Participant
    Master

    Same code as Despairs but without EMA15 and a time end for buy at 09:16, tested with 1 WF at 60% resulted in fib 1,5 on OMX 30.

    Andy

    defparam cumulateorders=false
    
    tradingtime=dayofweek>=1 and dayofweek<=5 and time>085900 and time<091600
    
    
    once tc=0
     
    if time=090000 then
    RangeTop=highest[11](high[1])
    RangeBottom=lowest[11](low[1])
    endif
     
    if intradaybarindex=0 then
    tc=0
    endif
    fib=fib
    CL=close>RangeTop and close[1]>RangeTop
    CS=close<RangeBottom and close[1]<RangeBottom
    box=RangeTop-RangeBottom
     
    if not onmarket and not tc and tradingtime then
    if CL  then
    buy 1 contract at market
    tc=1
    elsif CS   then
    sellshort 1 contract at market
    tc=1
    endif
    set target pprofit box*fib
    endif
     
    if longonmarket then
    sell at RangeBottom stop
    elsif shortonmarket then
    exitshort at RangeTop stop
    endif
    
    Nicolas and GraHal thanked this post
    #48651 quote
    Andyswede
    Participant
    Master

    Ooops, attached 3 times 🙂

    #48659 quote
    Eric
    Participant
    Master

    dont forget spread and slippage (sweden30)

    #48660 quote
    Andyswede
    Participant
    Master

    Spread was 0,9 should be ok I think, what do you mean with slippage Eric?

    #48661 quote
    Barney
    Participant
    Senior

    Looks really good.

    Backtest with 200k .. 🙂

    #48664 quote
    Eric
    Participant
    Master

    about slippage on sweden30, i mean if you get a bad fill on market order or stop around the open of cash market

    but run it on demo it may not be a problem after all?

    #48667 quote
    Stefanb
    Participant
    Senior

    Andy

    On my computer it looks like this.?

    Strange.

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

open range strategy code – lot of success


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
dillongr @dillongr Participant
Summary

This topic contains 38 replies,
has 10 voices, and was last updated by dillongr
7 years, 11 months ago.

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