Multi timeframe – MTF indicators for ProRealTime
04/10/2021 at 10:49 AM #166677
Agreed, it seems that the strategy back test is more accurate than the multi time frame computing within indicators. That is good to know.
It means also that when you do calculation with MTF with recursive indicators, you may need to display a huge number of bars to get an accurate result.
20 k bars of 1 minutes are approx 1333 bars of 15 minutes.
I slightly changed the indicator to add a count of the number 15 minute bars in the 1 minute graph.EMA and 15 minute Bar count in a 1 minute graph1234567891011121314timeframe(15 minute)MMA100M15 = (ExponentialAverage(close))MMA600M15 = (ExponentialAverage(close))Currentbar15= barindextimeframe(5 minute)MMA100M5 = (ExponentialAverage(close))MMA600M5 = (ExponentialAverage(close))timeframe(1 minute)MMA100M1 = (ExponentialAverage(close))MMA600M1 = (ExponentialAverage(close))return MMA100M15 as "iEMA100M15", MMA600M15 as "iEMA600M15", MMA100M5 as "iEMA100M5", MMA600M5 as "iEMA600M5", MMA100M1 as "iEMA100M1", MMA600M1 as "iEMA600M1", currentbar15 as "barsM15"
I created also an indicator to simply count the barindex on the M15 unit chart.
Result is follows, and might explain :04/10/2021 at 4:17 PM #166707
Actually there is another thing that seems constant but I have not seen it documented anywhere. May be I missed something. I yes, please send me the link to the documentation.
It seems there are always an extra 1000 bars loaded in the strategy tester / Back test WHATEVER the time frame. 1000 bars on M15, 1000 bars on M5, 1000 bars on M1 and so on.
Is there a parameter for this setting?
I modified the backtest as follows to add the number of bars seen in the BT on M15 and M1 timeframes:
sNbBarsM15 = barindex
sNbBarsM1 = barindexpb MTF in BT123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960// Définition des paramètres du codeDEFPARAM CumulateOrders = False // Cumul des positions désactivétimeframe(15 minute)MMA100M15 = (ExponentialAverage(close))MMA600M15 = (ExponentialAverage(close))sNbBarsM15 = barindextimeframe(5 minute)MMA100M5 = (ExponentialAverage(close))MMA600M5 = (ExponentialAverage(close))sNbBarsM5 = barindextimeframe(1 minute)MMA100M1 = (ExponentialAverage(close))MMA600M1 = (ExponentialAverage(close))sNbBarsM1 = barindexGraphonprice MMA100M15 as "sEMA100M15"Graphonprice MMA600M15 as "sEMA600M15"Graphonprice MMA100M5 as "sEMA100M5"Graphonprice MMA600M5 as "sEMA600M5"Graphonprice MMA100M1 as "sEMA100M1"Graphonprice MMA600M1 as "sEMA600M1"Graphonprice sNbBarsM15 as "sNbBarsM15"Graphonprice sNbBarsM5 as "sNbBarsM5"Graphonprice sNbBarsM1 as "sNbBarsM1"if BarIndex <8000 thenVosConditions = 1elseVosConditions = 0endif// généré automatiquement par PRT// Conditions pour ouvrir une position acheteuseIF NOT LongOnMarket AND VosConditions THENBUY 1 CONTRACTS AT MARKETENDIF// Conditions pour fermer une position acheteuseIf LongOnMarket AND VosConditions THENSELL AT MARKETENDIF// Conditions pour ouvrir une position en vente à découvertIF NOT ShortOnMarket AND VosConditions THENSELLSHORT 1 CONTRACTS AT MARKETENDIF// Conditions pour fermer une position en vente à découvertIF ShortOnMarket AND VosConditions THENEXITSHORT AT MARKETENDIF// Stops et objectifs : entrez vos stops et vos objectifs ici
Result is that there are 1000 more bars in the BT than displayed by an indicator :indicator in MTF123456789101112131415timeframe(15 minute)MMA100M15 = (ExponentialAverage(close))MMA600M15 = (ExponentialAverage(close))CurrentbarM15= barindextimeframe(5 minute)MMA100M5 = (ExponentialAverage(close))MMA600M5 = (ExponentialAverage(close))timeframe(1 minute)MMA100M1 = (ExponentialAverage(close))MMA600M1 = (ExponentialAverage(close))currentbarM1=barindexreturn MMA100M15 as "iEMA100M15", MMA600M15 as "iEMA600M15", MMA100M5 as "iEMA100M5", MMA600M5 as "iEMA600M5", MMA100M1 as "iEMA100M1", MMA600M1 as "iEMA600M1", currentbarM15 as "barsM15", currentbarM1 as "barsM1"04/10/2021 at 5:38 PM #16671804/10/2021 at 10:03 PM #166743
I know this setting for indicators. It cannot be used inside a strategy.
I was more speaking of what I found out for the Strategy back tester those 1000 bars added to each individual timeframe engine.
I think that in a backtest using MTF, there are as many isolated calculation engines as the number of time frames : one engine for each time frame, and each engine has 1000 extra bars are allocated at strategy launch.
Variables can be queried only from another time frame space.
I have seen no setting to change that extra 1000 bars number.04/10/2021 at 11:36 PM #16674404/11/2021 at 1:03 AM #166745
My mistake I tested it, it does change the number of bars preloaded on strategies
DEFPARAM PreLoadBars = 4000
gives 4000 bars preloaded for each time frame. and
DEFPARAM PreLoadBars = 0
gives the same number of bars on the indicator and on the strategy. Good to double check to check indicators and backtest computing are aligned.
it seems the default is 100006/07/2021 at 7:14 AM #171286
apologies of this is a dumb question but i am new to MTF coding & hope that i have it correct.
question is: if i have a 2 bollinger bands from 2 different time frames (say 1 min & 10 min) does it overlay the 10min onto the 1 min chart or does it get data from the 10min chart ie: the close & the bollinger from the 10min?
hoping this makes sense.12345678910timeframe (default, updateonclose)B1 = BollingerBandWidth(close)c1 = closetimeframe (10 minutes, updateonclose)B2 = BollingerBandWidth(close)c2 = closeif c1 < B1 and c2 < B2 thencount = 1endif06/07/2021 at 7:41 AM #171290
The way you placed your TIMEFRAMEs count is updated every 10 minutes as it’s part of that TF.
Move lines 1-3 to just below line 6 to make lines 8-10 part of the default TF (you can remove UpdateOnClose from the default TF, as it sets the pace and nothing can be updated there other than at closing time).
There you go:1234567891011timeframe (10 minutes, updateonclose)B2 = BollingerBandWidth(close)c2 = closetimeframe (default)B1 = BollingerBandWidth(close)c1 = close//if c1 < B1 and c2 < B2 thencount = 1endif06/08/2021 at 2:19 AM #17136607/03/2021 at 10:28 PM #173070
Been looking into MTF. I set up the following to verify my understanding of MTF operations but the results were not what I was expecting.
The setup… 2 charts, see screenshot, 1 and 2 minute both with basic price candles and default supertrend.
Below the main chart added a custom indicator, see code, to both, to give a binary indication of the price ‘close’ crossing the supertrend line.
Further, to the 1 min chart a second custom indicator using the same code as other but prefixed with ‘timeframe(2mn)’.
The chart labeling… Charts – 1Minute and 2Minute Indicators – A, B and C Areas of Interest – 1, 2 and 3
What I expected… On 1min and 2min charts, indicators [A] and [C]’s changes align up with the ‘close’, crossing the supertrend.
At this point I was expecting indicator [B] on 1min to display the same as [C] but it didn’t in several ways.
a) When [B] goes low at beginning of area 1, [C] is high, and the close doesn’t break supertrend.
b) Why does [B] stay low when [C] stays High cover area 1.
b) When [B] goes high at beginning of area 2, [C] goes high but not at same time.
c) Why when [B] goes low at end of area 2, [C] now does the same.
d) Why when [B] goes high then low at area 3, [C] also does.
e) bgnfgnstg (Banged head on keyboard!)
Investigation… After a bit of prodding and poking, here what i found.
After comparing the closing candles of both charts with the 2min supertrend I found that the unexpected changes on [B],(a)(c) aligned up with the close of 1min candles breaking the 2min supertrend before the 2min candles did. This also accounted for (c)(d) since the 1min candles didn’t’ reach the 2min supertrend before the 2min candles, the opposite.
However, I could find an explanation for (b) and why when the 2min prices closed above the 2min supertrend that [B] didn’t go back high but stay low until area 2 though it would have gone low prior to area 2.
Conclusion… In the scope of the TimeFrame(x) command, it appears that ‘close’, in this case, doesn’t refer to the (x) timeframe but the default or timeframe of the chart the indicators is in. Since price is an indicator I would expect this, but since a 2min candle is made up of two 1min candles it makes sense that the close of the first minute of a 2min candle could be lower of higher than the 2 minute.
Regarding (b) and why it stops low when all indications show it should have gone high I have no idea.
Over to you…code used for both indicators12345678910111213// uncomment timeframe for indicator [B]// timeframe(2mn)// code for custom indicator [A][C}if close crosses over Supertrend[3,10] thenline1=1elsif close crosses under Supertrend[3,10] thenline1=0.5endifreturn line107/04/2021 at 9:47 AM #17307807/04/2021 at 11:04 AM #173086
Thanks for replying.
- I was trying to understand how to use the TF function worked and verify results, not particularly creating an specific indicator.
- Getting 2minute data, indicator [C] results in the 1minute timeframe.
- Regarding the commented TF in the code. It is un-commented in the custom indicator for [B] but commented in [A][C] just copied same code when created NEW indicators .
Since sleeping on it and reading documentation it appears that most of problems I saw were because of not using the ‘MODE’ parameter in the TF syntax. In my code for indicator [B] it used the default TF update’s rather than update’s from the selected TF. This created a scenario were certain 1min close’s on the default TF triggered the condition in the selected TF code before the 2min closes could.
Using the Mode ‘UPDATEONCLOSE’ gave the results what I was originally expecting.
So problem solved. Thanks for responding09/16/2021 at 6:50 AM #177682
I have a indicator that returns a result. I run that Indicator on multiple frames open chart windows to visualize indicator and see when it triggers.
My question is can I add all the time frames that I want inside the code of the indicator then run it under one chart only and get it to return 1 when the indicator triggers in any of the coded timeframes without needing to visually open all the timeframe charts?09/16/2021 at 8:08 AM #177685
When MTF was first released for strategies there was a 6-TF limit. But it must have been removed as now I heve tested it for almost 12 (see pic Y).
This indicator works fine (applied to a 1-minute TF, using at least 10K units, as each daily bar requires roughly 1440 bars * 5-period average), see pic X:12345678910111213141516171819202122232425Timeframe(Daily,UpdateOnClose)sma1 = average[5,0](close)Timeframe(4h,UpdateOnClose)sma2 = average[5,0](close)Timeframe(1h,UpdateOnClose)sma3 = average[5,0](close)Timeframe(30 minute,UpdateOnClose)sma4 = average[5,0](close)Timeframe(15 minute,UpdateOnClose)sma5 = average[5,0](close)Timeframe(5 minute,UpdateOnClose)sma6 = average[5,0](close)Timeframe(8h,UpdateOnClose)sma7 = average[5,0](close)Timeframe(1 minute,UpdateOnClose)sma8 = average[5,0](close)Timeframe(default,UpdateOnClose)sma9 = average[5,0](close)Timeframe(Daily,default)sma10 = average[5,0](close)Timeframe(Daily,UpdateOnClose)sma11 = average[5,0](close)Timeframe(5 minute,default)sma12 = average[5,0](close)return sma1 as "sma1",sma2 as "sma2",sma3 as "sma3",sma4 as "sma4",sma5 as "sma5",sma6 as "sma6",sma7 as "sma7",sma8 as "sma8",sma9 as "sma9",sma10 as "sma10",sma11 as "sma11",sma12 as "sma12"09/16/2021 at 8:12 AM #177688
Bear in mind that you will have to apply your indicator to a chart with the smallest TF among those coded in your indicator AND that ALL the TFs used in your indicator must be a MULTIPLE of the default TF (the one on your chart).