Multi Timeframe Strategy Problem

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #91417 quote
    PZonda5
    Participant
    Veteran

    I was building a simple multi timeframe strategy based on the Absolute Strength indicator:

    Absolute Strength

    I am using the 3 Min chart of the Germany 30 Cash index as my current timeframe and the 15 Min chart for my higher timeframe.

    I am also using the Graph function to make sure I get the correct values for the Absolute Strenght lines.

    When looking at the Graph output, I noticed that when I use the condition “Timeframe(15 minutes,updateonclose)”, the Absolute Strength lines of the 15 Min timeframe slightly differ from the “true” values on the 15 Min chart.

    However, when I use the condition “Timeframe(15 minutes)” [without, updateonclose], the Absolute Strenght lines are correct.

    I would rather like to use the updateonclose condition for my strategy, so I would like to find out why this difference exist and if it can be fixed?

     

    Below you can find my code and some screenshots to further illustrate my problem (I realise it probably isn’t the best looking code, especially the way I handled the MTF bit, but thats due to my lack in coding experience – mayby that’s why I have this problem in the first place)

    //-------------------------------------------------------------------------
    // Main code : AbsStrength (3M) - Concept 8
    //-------------------------------------------------------------------------
    
    Defparam Cumulateorders = False
    
    //15 minute timeframe conditions
    Timeframe(15 minutes,updateonclose)
    
    //Absolute Strength Indicator START
    // --- settings
    ModeMTF   = 1   // 0-RSI method 1-Stoch method
    LengthMTF = 9 // Period
    SmoothMTF = 1 // Period of smoothing
    ModeMAMTF = 2 // Mode of Moving Average
    // --- end of settings
    
    if barindex>max(LengthMTF,SmoothMTF) then
    Price1MTF=customclose
    Price2MTF=customclose[1]
    
    if ModeMTF=0 then
    BullsMTF=0.5*(Abs(Price1MTF-Price2MTF)+(Price1MTF-Price2MTF))
    BearsMTF=0.5*(Abs(Price1MTF-Price2MTF)-(Price1MTF-Price2MTF))
    endif
    if ModeMTF=1 then
    smaxMTF=Highest[LengthMTF](high)
    sminMTF=Lowest[LengthMTF](low)
    BullsMTF=Price1MTF - sminMTF
    BearsMTF=smaxMTF - Price1MTF
    endif
    
    AvgBullsMTF=average[LengthMTF,ModeMAMTF](BullsMTF)
    AvgBearsMTF=average[LengthMTF,ModeMAMTF](BearsMTF)
    
    SmthBullsMTF=average[SmoothMTF,ModeMAMTF](AvgBullsMTF)
    SmthBearsMTF=average[SmoothMTF,ModeMAMTF](AvgBearsMTF)
    endif
    //Absolute Strength Indicator END
    
    //"default" timeframe conditions
    Timeframe(default)
    
    //Size & Targets
    Positionsize = 1
    
    PTL = 10
    SLL = 10
    PTS = 10
    SLS = 10
    
    // Day & Time
    Once Entertime = 090000
    Once Lasttime  = 173000
    
    Tt1 = Time >= Entertime
    Tt2 = Time <= Lasttime
    Tradetime = Tt1 And Tt2
    
    //Absolute Strength Indicator START
    // --- settings
    Mode   = 1   // 0-RSI method 1-Stoch method
    Length = 9 // Period
    Smooth = 1 // Period of smoothing
    ModeMA = 2 // Mode of Moving Average
    // --- end of settings
    
    if barindex>max(Length,Smooth) then
    Price1=customclose
    Price2=customclose[1]
    
    if Mode=0 then
    Bulls=0.5*(Abs(Price1-Price2)+(Price1-Price2))
    Bears=0.5*(Abs(Price1-Price2)-(Price1-Price2))
    endif
    if Mode=1 then
    smax=Highest[Length](high)
    smin=Lowest[Length](low)
    Bulls=Price1 - smin
    Bears=smax - Price1
    endif
    
    AvgBulls=average[Length,ModeMA](Bulls)
    AvgBears=average[Length,ModeMA](Bears)
    
    SmthBulls=average[Smooth,ModeMA](AvgBulls)
    SmthBears=average[Smooth,ModeMA](AvgBears)
    endif
    //Absolute Strength Indicator END
    
    //"default" timeframe
    Timeframe(default)
    
    //Entry & Exit Conditions
    If Tradetime Then
    If SmthBulls>SmthBears and SmthBulls[1]<SmthBears[1] and SmthBullsMTF>SmthBearsMTF and SmthBullsMTF>SmthBullsMTF[1] and SmthBearsMTF<SmthBearsMTF[1] Then
    Buy Positionsize Contract At Market
    SET TARGET PROFIT PTL
    Set Stop loss SLL
    Endif
    Endif
    
    If Tradetime Then
    If SmthBulls<SmthBears and SmthBulls[1]>SmthBears[1] and SmthBullsMTF<SmthBearsMTF and SmthBullsMTF<SmthBullsMTF[1] and SmthBearsMTF>SmthBearsMTF[1] Then
    Sellshort Positionsize Contract At Market
    SET TARGET PROFIT PTS
    Set Stop loss SLS
    Endif
    Endif
    
    
    graph SmthBullsMTF coloured(0,191,255)
    graph SmthBearsMTF coloured(255,0,0)
    
    graph SmthBulls coloured (0,300,0)
    graph SmthBears coloured (300,0,0)
    
    AbsStrength-3M-Concept-8.itf With-Updateonclose.png With-Updateonclose.png Without-Updateonclose.png Without-Updateonclose.png
    #91421 quote
    robertogozzi
    Moderator
    Master

    I modified your code by adding a coiuple of TF’s and GRAPH’s so that you can see the inner workings of BARINDEX, which is likely to be the cause of your issue (I indented my line 6 spaces):

    //-------------------------------------------------------------------------
    // Main code : AbsStrength (3M) - Concept 8
    //-------------------------------------------------------------------------
     
    Defparam Cumulateorders = False
    defparam preloadbars=0
    //15 minute timeframe conditions
    Timeframe(15 minutes,updateonclose)
     
    //Absolute Strength Indicator START
    // --- settings
    ModeMTF   = 1   // 0-RSI method 1-Stoch method
    LengthMTF = 9 // Period
    SmoothMTF = 1 // Period of smoothing
    ModeMAMTF = 2 // Mode of Moving Average
    // --- end of settings
     
    if barindex>max(LengthMTF,SmoothMTF) then
    Price1MTF=customclose
    Price2MTF=customclose[1]
     
    if ModeMTF=0 then
    BullsMTF=0.5*(Abs(Price1MTF-Price2MTF)+(Price1MTF-Price2MTF))
    BearsMTF=0.5*(Abs(Price1MTF-Price2MTF)-(Price1MTF-Price2MTF))
    endif
    if ModeMTF=1 then
    smaxMTF=Highest[LengthMTF](high)
    sminMTF=Lowest[LengthMTF](low)
    BullsMTF=Price1MTF - sminMTF
    BearsMTF=smaxMTF - Price1MTF
    endif
     
    AvgBullsMTF=average[LengthMTF,ModeMAMTF](BullsMTF)
    AvgBearsMTF=average[LengthMTF,ModeMAMTF](BearsMTF)
     
    SmthBullsMTF=average[SmoothMTF,ModeMAMTF](AvgBullsMTF)
    SmthBearsMTF=average[SmoothMTF,ModeMAMTF](AvgBearsMTF)
    endif
          x1 = barindex
          graph x1
    
          Timeframe(15 minutes,default)
                x2 = barindex
                graph x2
    
    //Absolute Strength Indicator END
     
    //"default" timeframe conditions
    Timeframe(default)
          x3 = barindex
          graph x3
    //Size & Targets
    Positionsize = 1
     
    PTL = 10
    SLL = 10
    PTS = 10
    SLS = 10
     
    // Day & Time
    Once Entertime = 090000
    Once Lasttime  = 173000
     
    Tt1 = Time >= Entertime
    Tt2 = Time <= Lasttime
    Tradetime = Tt1 And Tt2
     
    //Absolute Strength Indicator START
    // --- settings
    Mode   = 1   // 0-RSI method 1-Stoch method
    Length = 9 // Period
    Smooth = 1 // Period of smoothing
    ModeMA = 2 // Mode of Moving Average
    // --- end of settings
     
    if barindex>max(Length,Smooth) then
    Price1=customclose
    Price2=customclose[1]
     
    if Mode=0 then
    Bulls=0.5*(Abs(Price1-Price2)+(Price1-Price2))
    Bears=0.5*(Abs(Price1-Price2)-(Price1-Price2))
    endif
    if Mode=1 then
    smax=Highest[Length](high)
    smin=Lowest[Length](low)
    Bulls=Price1 - smin
    Bears=smax - Price1
    endif
     
    AvgBulls=average[Length,ModeMA](Bulls)
    AvgBears=average[Length,ModeMA](Bears)
     
    SmthBulls=average[Smooth,ModeMA](AvgBulls)
    SmthBears=average[Smooth,ModeMA](AvgBears)
    endif
    //Absolute Strength Indicator END
     
    //"default" timeframe
    Timeframe(default)
     
    //Entry & Exit Conditions
    If Tradetime Then
    If SmthBulls>SmthBears and SmthBulls[1]<SmthBears[1] and SmthBullsMTF>SmthBearsMTF and SmthBullsMTF>SmthBullsMTF[1] and SmthBearsMTF<SmthBearsMTF[1] Then
    Buy Positionsize Contract At Market
    SET TARGET PROFIT PTL
    Set Stop loss SLL
    Endif
    Endif
     
    If Tradetime Then
    If SmthBulls<SmthBears and SmthBulls[1]>SmthBears[1] and SmthBullsMTF<SmthBearsMTF and SmthBullsMTF<SmthBullsMTF[1] and SmthBearsMTF>SmthBearsMTF[1] Then
    Sellshort Positionsize Contract At Market
    SET TARGET PROFIT PTS
    Set Stop loss SLS
    Endif
    Endif
     
     
    graph SmthBullsMTF coloured(0,191,255)
    graph SmthBearsMTF coloured(255,0,0)
    
    graph SmthBulls coloured (0,300,0)
    graph SmthBears coloured (300,0,0)
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Multi Timeframe Strategy Problem


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
PZonda5 @pzonda5 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
7 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/14/2019
Status: Active
Attachments: 3 files
Logo Logo
Loading...