m_b_round

Dual timeframe calculated candles

m_b_round 已更新   
A script example to show how you can calculate the value of certain indicators from a higher timeframe at the moment that a bar closes on a shorter timeframe.

In this example the base chart is set to 5 mins and the multiplier is set to 6, so the HTF arrays hold data equivalent to that from the 30 minute chart which will hopefully appear below it on this display.

Each time a 5 minute bar completes, the arrays are updated by checking whether a new high or low has been set. The values for the HTF ATR and EMA are also updated by removing the most recent value from that array and replacing it with the value that would have been calculated based on the close at that time. As such for back testing purposes you'd know exactly what the 30 min chart would have been showing you at any one of the 5 minute intervals. Useful for backtesting strategies if you would rather act on the "up to the minute" HTF data, rather than the HTF data from the last HTF close, which could be significantly delayed if you're using a high enough multiplier.
發布通知:
Chart update for clarity. Green line is the EMA function applied to the chart with its timeframe set to 30 mins. As you'll see it coincides with the values the script calculates every 6 bars, but between those times the calculated EMA differs as the close from each 5 min candle would change the most up to date HTF line as well.
發布通知:
Removed the option of setting how many HTF bars to keep. If this was set to a value less than the EMA length, then the HTF EMA never initialised properly.

It's probably not needed to trim the arrays for memory purposes, but just in case the arrays are now trimmed to 110% of the emaLength (plus 2 more for good measure).
開源腳本

本著真正的TradingView精神,該腳本的作者將其開源發布,以便交易者可以理解和驗證它。為作者喝彩吧!您可以免費使用它,但在出版物中重複使用此代碼受網站規則的約束。 您可以收藏它以在圖表上使用。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?