How can I make these HTF shapes fixed to the first candle where the HTF label first appeared?

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

New contributor

tren10x is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật