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.
Problems…
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…
// uncomment timeframe for indicator [B]
// timeframe(2mn)
// code for custom indicator [A][C}
if close crosses over Supertrend[3,10] then
line1=1
elsif close crosses under Supertrend[3,10] then
line1=0.5
endif
return line1