I’ve successfully implemented multi-timeframe (MTF) functionality in my TradingView script, allowing higher timeframe (HTF) labels to be displayed on lower timeframes. However, I’m encountering a specific problem with how these HTF labels are being positioned.
Currently, when the HTF labels are set to Daily, they always appear fixed to the last candle of the session on the lower timeframes. This is causing some confusion because I need the HTF shapes to remain anchored to the first candle where the HTF label initially appeared, rather than shifting to the last candle of the session.
Here’s a breakdown of the issue:
Objective: Display HTF labels (e.g., Daily) on lower timeframes.
Current Behavior: HTF labels are fixed to the last candle of the session on lower timeframes.
Desired Behavior: HTF shapes should stick to the first candle where the HTF label first appeared on the lower timeframe chart.
HTF = input.timeframe("D", "Higher Timeframe")
resolution = timeframe.period
ha_close = request.security(syminfo.tickerid, resolution, (open + high + low + close) / 4)
ha_open := na(ha_open) ? request.security(syminfo.tickerid, resolution, (open + close) / 2) : (ha_open[1] + ha_close[1]) / 2
ha_high = math.max(high, math.max(ha_open, ha_close))
ha_low = math.min(low, math.min(ha_open, ha_close))
ha_color1 = ha_close > ha_open ? #089981 : #ef5350
ha_closeHTF = request.security(syminfo.tickerid, HTF, (open + high + low + close) / 4)
ha_openHTF := na(ha_openHTF) ? request.security(syminfo.tickerid, HTF, (open + close) / 2) : (ha_openHTF[1] + ha_closeHTF[1]) / 2
ha_highHTF = math.max(high, math.max(ha_openHTF, ha_closeHTF))
ha_lowHTF = math.min(low, math.min(ha_openHTF, ha_closeHTF))
ha_colorHTF = ha_closeHTF > ha_openHTF ? #089981 : #ef5350
buy_signalzz = ha_color1 != ha_color1[1] and ha_color1 == #089981
sell_signalzz = ha_color1 != ha_color1[1] and ha_color1 == #ef5350
buy_signalHTF = ha_colorHTF != ha_colorHTF[1] and ha_colorHTF == #089981
sell_signalHTF = ha_colorHTF != ha_colorHTF[1] and ha_colorHTF == #ef5350
buy_signal = request.security(syminfo.tickerid, resolution, buy_signalzz, lookahead=barmerge.lookahead_on)
sell_signal = request.security(syminfo.tickerid, resolution, sell_signalzz, lookahead=barmerge.lookahead_on)
buy_signal2 = request.security(syminfo.tickerid, HTF, buy_signalHTF, lookahead=barmerge.lookahead_on)
sell_signal2 = request.security(syminfo.tickerid, HTF, sell_signalHTF, lookahead=barmerge.lookahead_on)
// Plot shapes for current timeframe signals
plotchar(enabledOG and buy_signal, title="Buy Shape Style", char="↑", location=location.belowbar, color=buyShapeColor, size=size.small, editable=true, show_last=showMostRecentShapes ? 24 : maxRecentShapes, display=display.none)
plotchar(enabledOG and sell_signal, title="Sell Shape Style", char="↓", location=location.abovebar, color=sellShapeColor, size=size.small, editable=true, show_last=showMostRecentShapes ? 24 : maxRecentShapes, display=display.none)
// Plot shapes for Higher Timeframe signals
plotchar(enabled and buy_signal2 and not buy_signal2[1], title="HTF Buy Shape Style", char="⇡", location=location.belowbar, color=HTFBuyShapeColor, size=size.small, editable=true, show_last=showMostRecentHTFShapes ? 500 : maxRecentHTFShapes)
plotchar(enabled and sell_signal2[2] and not sell_signal2[1], title="HTF Sell Shape Style", char="⇣", location=location.abovebar, color=HTFSellShapeColor, size=size.small, editable=true, show_last=showMostRecentHTFShapes ? 500 : maxRecentHTFShapes)
plotchar(enabled and Show1 and buy_signal2 and not buy_signal2[1], title="HTF Buy Shape (Past)", location=location.belowbar, char="⇡", color=HTFBuyShapeColor, size=size.small, editable=true, show_last=showMostRecentHTFShapes ? 2000 : maxRecentHTFShapes)
plotchar(enabled and Show1 and sell_signal2 and not sell_signal2[1], title="HTF Sell Shape (Past)", location=location.abovebar, char="⇣", color=HTFSellShapeColor, size=size.small, editable=true, show_last=showMostRecentHTFShapes ? 2000 : maxRecentHTFShapes)
I’ve attempted to anchor these shapes or labels to specific candles, but found that they always adjust to the last candle of the session on lower timeframes. I want the HTF shapes or labels to be fixed to the first candle where the HTF label originally appeared, rather than shifting to the last candle of the session. Ideally, the HTF labels should maintain their position relative to the first occurrence on the lower timeframe chart, regardless of the current session’s end.
Thanks in advance
tren10x is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.