Dax Breakout – Need some assistance please

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #223505 quote
    PatMc
    Participant
    New

    Hi,

     

    Posted this initially in the wrong forum, posting again correctly.

    I am new to this forum and new to coding in general but hoping you can help.

    I want to produce a strategy that takes the high and low of the 7:45-8am bar (UK). If the market goes 5 points above the high it’s a (buy), if 5 points below the low it triggers a sell. 20 point stop loss with a 40 point profit target. If one trade triggers the other is cancelled.

    I think the below captures it but I might be wrong (I took a lot of it from a previous code I found and made amendments).

    Lastly, and this is the part I need help with. If the trade is 15 points in my favour the stop loss moves to 0 or breakeven and I am not sure how to code that.

    Any help would be greatly appreciated. Thanks.

     

    DEFPARAM cumulateOrders = false
    //—————————————–
    timeframe (1 minute)
    OTD = Barindex – TradeIndex(1) > IntradayBarIndex //one trade X day
    startHour = 080000
    cTime = time >= startHour
    //——————————————————
    if openTime = 074500 then
    myHighest = high
    myLowest = low
    endif
    if openTime >= 074500 and openTime <=075959 then
    myHighest = max (myHighest,high)
    myLowest = min (myLowest,low)
    endif
    //————————————————————–
    if not onMarket and cTime and OTD then
    buy 1 contract at myHighest + (5*pointSize) stop
    sellShort 1 contract at myLowest – (5*pointSize) stop
    endif
    //—————————————————————–
    SET STOP LOSS 20
    set target pProfit 40

    #223507 quote
    robertogozzi
    Moderator
    Master

    The code seems correct and pending orders are automatically cancelled at the closing of each bar. They need to be placed again if needed.

    There might be a minor chance that both pending orders are triggered, if that occurs on the same bar. It’s not possible to prevent that from happening (DEFPARAM cumulateOrders = false is of no use in this case).

    The only correction I have made is to tell a STOP from a LIMIT order:

    DEFPARAM cumulateOrders = false
    //—————————————-
    timeframe (1 minute)
    OTD = Barindex - TradeIndex(1) > IntradayBarIndex //one trade X day
    startHour = 080000
    cTime = time >= startHour
    //——————————————————
    if openTime = 074500 then
       myHighest = high
       myLowest  = low
    endif
    if openTime >= 074500 and openTime <=075959 then
       myHighest = max (myHighest,high)
       myLowest  = min (myLowest,low)
    endif
    //————————————————————-
    if not onMarket and cTime and OTD then
       IF close > myHighest THEN
          buy       1 contract at myHighest + (5*pointSize) limit
       ELSIF close < myHighest THEN
          buy       1 contract at myHighest + (5*pointSize) stop
       ENDIF
       IF close > myLowest THEN
          sellShort 1 contract at myLowest  - (5*pointSize) stop
       ELSIF close < myLowest THEN
          sellShort 1 contract at myLowest  - (5*pointSize) limit
       ENDIF
    endif
    //—————————————————————-
    SET STOP   pLOSS   20
    set target pProfit 40
    #223509 quote
    PatMc
    Participant
    New

    Hi Roberto,

    Thanks very much for looking at this.

    Am I correct in saying “if the buy signal and the sell signal both trigger within the same 1 minute bar then both trades will trigger” but if they appear in different 1 min bars this will not happen?

    Also, I mentioned moving my 20 point stop loss to Breakeven or 0 when I am 15 points in profit. Would you be able to assist with that?

    #223510 quote
    MauroPro
    Participant
    Veteran

    If you wanto to bring the stop to breakeven after 15 points add to your code this snippet.

    if not onMarket then
    myExit = 0
    endif
    if longOnMarket and myExit = 0 and (close - tradePrice) >= 15 * pointSize then
    myExit = tradePrice(1)
    elsIf shortOnMarket and myExit = 0 and (tradePrice - close) >= 15 * pointSize then
    myExit = tradePrice(1)
    endif
    if myExit > 0 then
    sell at myExit STOP
    exitShort at myExit STOP
    endif
    robertogozzi and PatMc thanked this post
    #223513 quote
    robertogozzi
    Moderator
    Master

    PatMc, you are absolutely right.

    MauroPro coded an effective snippet for beeakeven. This is his example modified to use different instructions:

    if (longOnMarket and (close - tradePrice) >= 15 * pointSize) OR (shortOnMarket and (tradePrice - close) >= 15 * pointSize) then
       set Stop Breakeven
    endif
    f1_maik and PatMc thanked this post
    #223514 quote
    MauroPro
    Participant
    Veteran

    Hi Roberto, I tried your code with the new instruction but it doesn’t hit the breakeven point. I had already tried it, written in a different way, before inserting the classical snippet, and also to me it didn’t work either (I thought I made a mistake).

    Could you check?

    #223515 quote
    MauroPro
    Participant
    Veteran

    This is the way I had written (but it didn’t work) the code with the new instruction (the old snippet work fine):

     

    floatingPosition = positionPrice*positionPerf/pointSize

    if (longOnMarket or shortOnMarket) and floatingPosition > 15*pointSize then
    set stop breakeven
    endif

    PatMc thanked this post
    #223917 quote
    slumpy man
    Participant
    New

    How could the code be changed to put at 1 or 2 points in profit instead of just break even?

    #223920 quote
    MauroPro
    Participant
    Veteran

    In line 5 and 7 you have to write:

    myExit = tradePrice(1) + 2*pointSize

    slumpy man thanked this post
    #224093 quote
    PatMc
    Participant
    New

    Hi, I have noticed the coding produces results on a sunday evening and I would like to exclude this from the below. I tried what I thought was correct but doesn’t work.

     

    DEFPARAM cumulateOrders = false
    //—————————————-
    timeframe (1 minute)
    OTD = Barindex – TradeIndex(1) > IntradayBarIndex //one trade X day
    startHour = 080000
    cTime = time >= startHour
    //——————————————————
    if openTime = 074500 then
    myHighest = high
    myLowest = low
    endif
    if openTime >= 074500 and openTime <=075959 then myHighest = max (myHighest,high) myLowest = min (myLowest,low) endif //————————————————————- if not onMarket and cTime and OTD then IF close > myHighest THEN
    buy 1 contract at myHighest + (5*pointSize) limit
    ELSIF close < myHighest THEN buy 1 contract at myHighest + (5*pointSize) stop ENDIF IF close > myLowest THEN
    sellShort 1 contract at myLowest – (5*pointSize) stop
    ELSIF close < myLowest THEN
    sellShort 1 contract at myLowest – (5*pointSize) limit
    ENDIF
    endif
    //—————————————————————-
    SET STOP pLOSS 20
    set target pProfit 40

    #224104 quote
    MauroPro
    Participant
    Veteran

    Just add to your code: “dayOfWeek” (monday = 1, tuesday = 2 …):

    if (dayOfWeek >= 1 and dayOfWeek <= 5) and not onMarket and cTime and OTD then

    PatMc thanked this post
    #224202 quote
    PatMc
    Participant
    New

    Hi all,

    I am not sure the coding gives me what I thought it was.

    In summary, I expect the code to provide me with the high and low between 0745am and 0759am -minute bar. It would then trigger a buy or sell if the market hits 5 points below those bars’ high or low.

    For example: On November 23rd the high and low of the DAX between 07:45am and 07:59am was 15,961.4 and 15948.4. This would mean a buy is triggered at 15,966.4 (15,961.4 + 5 points) and a sell would be triggered at  15943.4 (15948.4 – 5 points).

    The trade triggered a sell at 15946.4 which is 3 points less than it should do and at no point did it reach 15943.4 to trigger a sell but the system triggered a sell at 08:01 at 15946.4 and proceeded to lose 20 points. I note that all the entries happen at the start of a new bar so I believe it will only ever trigger at the close of previous bar but I don’t understand why it triggered in the first place if the buy/sell at high/low + 5 is working properly.

    Any help is greatly appreciated and thanks for all the assistance provided so far 🙂

     

    DEFPARAM cumulateOrders = false
    //—————————————-
    timeframe (1 minute)
    OTD = Barindex TradeIndex(1) > IntradayBarIndex //one trade X day
    startHour = 080000
    cTime = time >= startHour
    //——————————————————
    if openTime = 074500 then
       myHighest = high
       myLowest  = low
    endif
    if openTime >= 074500 and openTime <=075959 then
       myHighest = max (myHighest,high)
       myLowest  = min (myLowest,low)
    endif
    //————————————————————-
    if not onMarket and cTime and OTD then
       IF close > myHighest THEN
          buy       1 contract at myHighest + (5*pointSize) limit
       ELSIF close < myHighest THEN
          buy       1 contract at myHighest + (5*pointSize) stop
       ENDIF
       IF close > myLowest THEN
          sellShort 1 contract at myLowest   (5*pointSize) stop
       ELSIF close < myLowest THEN
          sellShort 1 contract at myLowest   (5*pointSize) limit
       ENDIF
    endif
    //—————————————————————-
    SET STOP   pLOSS   20
    set target pProfit 40
    #224207 quote
    JS
    Participant
    Senior

    Hi,

    Calculating the highest and lowest values doesn’t go well…

    (if you want to know why, please let me know)

    Try these:

    If OpenTime=075900 then

    myHighest=Highest[15](High)

    myLowest=Lowest[15](Low)

    EndIf

    In the next part:

    Omit these sentences:

    If Close>myHighset then

    If Close>myLowest then

    PatMc thanked this post
    #224208 quote
    MauroPro
    Participant
    Veteran
    In your formula you have typed:  close > myLowest, instead you have to write close < myLowest. Also use graphOnPrice to see the buy – sell levels. You can also add this INDICATOR to see the max and min of the chosen time:
    // rangeBox time1 - time2
    
    time1 = 074500
    time2 = 080000
    
    if openTime = time1 then
    bar1 = barIndex
    hh   = high
    ll   = low
    endif
    hh = max(hh,high)
    ll = min(ll,low)
    //-------------------------------------------------
    if time = time2 then
    bar2 = barIndex
    endif
    if bar2 > bar1 then
    drawRectangle(bar1,hh,bar2,ll) coloured(255,0,0,25) borderColor(0,255,0,155)
    bar2 = 0
    endif
    
    return
    
    Here is the simplest formula:
    DEFPARAM cumulateOrders = false
    //—————————————-
    timeframe (1 minute)
    OTD = Barindex - TradeIndex(1) > IntradayBarIndex //one trade X day
    startHour = 080000
    cTime = time >= startHour
    //——————————————————
    if openTime = 074500 then
    myHighest = high
    myLowest  = low
    endif
    if openTime >= 074500 and openTime <= 075900 then
    myHighest = max (myHighest,high)
    myLowest  = min (myLowest,low)
    endif
    //————————————————————-
    if not onMarket and cTime and OTD then
    buy 1 contract at myHighest + (5*pointSize) stop
    sellShort 1 contract at myLowest - (5*pointSize) stop
    endif
    //—————————————————————-
    SET STOP   pLOSS   20
    set target pProfit 40
    
    
    graphonPrice myHighest + (5*pointSize)
    graphOnPrice  myLowest  - (5*pointSize)
    I add a picture of the day 23 you were referring to.
    PatMc thanked this post
    #224210 quote
    MauroPro
    Participant
    Veteran
    This would be the formula with the advice of JS (the result is the same, test 200K).  
    DEFPARAM cumulateOrders = false
    //—————————————-
    timeframe (1 minute)
    OTD = Barindex - TradeIndex(1) > IntradayBarIndex //one trade X day
    startHour = 080000
    cTime = time >= startHour
    //——————————————————
    If OpenTime=075900 then
    myHighest=Highest[15](High)
    myLowest=Lowest[15](Low)
    endif
    //————————————————————-
    if not onMarket and cTime and OTD then
    buy 1 contract at myHighest + (5*pointSize) stop
    sellShort 1 contract at myLowest - (5*pointSize) stop
    endif
    //—————————————————————-
    SET STOP   pLOSS   20
    set target pProfit 40
    
    
    graphonPrice myHighest + (5*pointSize)
    graphOnPrice  myLowest  - (5*pointSize)
    PatMc thanked this post
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

Dax Breakout – Need some assistance please


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
PatMc @patmceniry Participant
Summary

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

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