Multi Timeframe Strategy Problem
Forums › ProRealTime English forum › ProOrder support › Multi Timeframe Strategy Problem
- This topic has 1 reply, 2 voices, and was last updated 5 years ago by robertogozzi.
-
-
02/14/2019 at 5:35 PM #91417
I was building a simple multi timeframe strategy based on the Absolute Strength indicator:
https://www.prorealcode.com/prorealtime-indicators/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)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116//-------------------------------------------------------------------------// Main code : AbsStrength (3M) - Concept 8//-------------------------------------------------------------------------Defparam Cumulateorders = False//15 minute timeframe conditionsTimeframe(15 minutes,updateonclose)//Absolute Strength Indicator START// --- settingsModeMTF = 1 // 0-RSI method 1-Stoch methodLengthMTF = 9 // PeriodSmoothMTF = 1 // Period of smoothingModeMAMTF = 2 // Mode of Moving Average// --- end of settingsif barindex>max(LengthMTF,SmoothMTF) thenPrice1MTF=customclosePrice2MTF=customclose[1]if ModeMTF=0 thenBullsMTF=0.5*(Abs(Price1MTF-Price2MTF)+(Price1MTF-Price2MTF))BearsMTF=0.5*(Abs(Price1MTF-Price2MTF)-(Price1MTF-Price2MTF))endifif ModeMTF=1 thensmaxMTF=Highest[LengthMTF](high)sminMTF=Lowest[LengthMTF](low)BullsMTF=Price1MTF - sminMTFBearsMTF=smaxMTF - Price1MTFendifAvgBullsMTF=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 conditionsTimeframe(default)//Size & TargetsPositionsize = 1PTL = 10SLL = 10PTS = 10SLS = 10// Day & TimeOnce Entertime = 090000Once Lasttime = 173000Tt1 = Time >= EntertimeTt2 = Time <= LasttimeTradetime = Tt1 And Tt2//Absolute Strength Indicator START// --- settingsMode = 1 // 0-RSI method 1-Stoch methodLength = 9 // PeriodSmooth = 1 // Period of smoothingModeMA = 2 // Mode of Moving Average// --- end of settingsif barindex>max(Length,Smooth) thenPrice1=customclosePrice2=customclose[1]if Mode=0 thenBulls=0.5*(Abs(Price1-Price2)+(Price1-Price2))Bears=0.5*(Abs(Price1-Price2)-(Price1-Price2))endifif Mode=1 thensmax=Highest[Length](high)smin=Lowest[Length](low)Bulls=Price1 - sminBears=smax - Price1endifAvgBulls=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" timeframeTimeframe(default)//Entry & Exit ConditionsIf Tradetime ThenIf SmthBulls>SmthBears and SmthBulls[1]<SmthBears[1] and SmthBullsMTF>SmthBearsMTF and SmthBullsMTF>SmthBullsMTF[1] and SmthBearsMTF<SmthBearsMTF[1] ThenBuy Positionsize Contract At MarketSET TARGET PROFIT PTLSet Stop loss SLLEndifEndifIf Tradetime ThenIf SmthBulls<SmthBears and SmthBulls[1]>SmthBears[1] and SmthBullsMTF<SmthBearsMTF and SmthBullsMTF<SmthBullsMTF[1] and SmthBearsMTF>SmthBearsMTF[1] ThenSellshort Positionsize Contract At MarketSET TARGET PROFIT PTSSet Stop loss SLSEndifEndifgraph SmthBullsMTF coloured(0,191,255)graph SmthBearsMTF coloured(255,0,0)graph SmthBulls coloured (0,300,0)graph SmthBears coloured (300,0,0)02/14/2019 at 6:07 PM #91421I 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):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124//-------------------------------------------------------------------------// Main code : AbsStrength (3M) - Concept 8//-------------------------------------------------------------------------Defparam Cumulateorders = Falsedefparam preloadbars=0//15 minute timeframe conditionsTimeframe(15 minutes,updateonclose)//Absolute Strength Indicator START// --- settingsModeMTF = 1 // 0-RSI method 1-Stoch methodLengthMTF = 9 // PeriodSmoothMTF = 1 // Period of smoothingModeMAMTF = 2 // Mode of Moving Average// --- end of settingsif barindex>max(LengthMTF,SmoothMTF) thenPrice1MTF=customclosePrice2MTF=customclose[1]if ModeMTF=0 thenBullsMTF=0.5*(Abs(Price1MTF-Price2MTF)+(Price1MTF-Price2MTF))BearsMTF=0.5*(Abs(Price1MTF-Price2MTF)-(Price1MTF-Price2MTF))endifif ModeMTF=1 thensmaxMTF=Highest[LengthMTF](high)sminMTF=Lowest[LengthMTF](low)BullsMTF=Price1MTF - sminMTFBearsMTF=smaxMTF - Price1MTFendifAvgBullsMTF=average[LengthMTF,ModeMAMTF](BullsMTF)AvgBearsMTF=average[LengthMTF,ModeMAMTF](BearsMTF)SmthBullsMTF=average[SmoothMTF,ModeMAMTF](AvgBullsMTF)SmthBearsMTF=average[SmoothMTF,ModeMAMTF](AvgBearsMTF)endifx1 = barindexgraph x1Timeframe(15 minutes,default)x2 = barindexgraph x2//Absolute Strength Indicator END//"default" timeframe conditionsTimeframe(default)x3 = barindexgraph x3//Size & TargetsPositionsize = 1PTL = 10SLL = 10PTS = 10SLS = 10// Day & TimeOnce Entertime = 090000Once Lasttime = 173000Tt1 = Time >= EntertimeTt2 = Time <= LasttimeTradetime = Tt1 And Tt2//Absolute Strength Indicator START// --- settingsMode = 1 // 0-RSI method 1-Stoch methodLength = 9 // PeriodSmooth = 1 // Period of smoothingModeMA = 2 // Mode of Moving Average// --- end of settingsif barindex>max(Length,Smooth) thenPrice1=customclosePrice2=customclose[1]if Mode=0 thenBulls=0.5*(Abs(Price1-Price2)+(Price1-Price2))Bears=0.5*(Abs(Price1-Price2)-(Price1-Price2))endifif Mode=1 thensmax=Highest[Length](high)smin=Lowest[Length](low)Bulls=Price1 - sminBears=smax - Price1endifAvgBulls=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" timeframeTimeframe(default)//Entry & Exit ConditionsIf Tradetime ThenIf SmthBulls>SmthBears and SmthBulls[1]<SmthBears[1] and SmthBullsMTF>SmthBearsMTF and SmthBullsMTF>SmthBullsMTF[1] and SmthBearsMTF<SmthBearsMTF[1] ThenBuy Positionsize Contract At MarketSET TARGET PROFIT PTLSet Stop loss SLLEndifEndifIf Tradetime ThenIf SmthBulls<SmthBears and SmthBulls[1]>SmthBears[1] and SmthBullsMTF<SmthBearsMTF and SmthBullsMTF<SmthBullsMTF[1] and SmthBearsMTF>SmthBearsMTF[1] ThenSellshort Positionsize Contract At MarketSET TARGET PROFIT PTSSet Stop loss SLSEndifEndifgraph SmthBullsMTF coloured(0,191,255)graph SmthBearsMTF coloured(255,0,0)graph SmthBulls coloured (0,300,0)graph SmthBears coloured (300,0,0) -
AuthorPosts
Find exclusive trading pro-tools on