EsIstTurnt

Higher TimeFrame Smooth Moving Averages

Script is designed for those who dislike how plotting a moving average from a higher timeframe on a lower timeframe chart results in a choppy zigzag line when using the standard request.security(syminfo.ticker,"x",ta.sma(src,len)) method.

My more elegant solution was to translate the chart's current timeframe, and the selected higher timeframe into seconds, then check if selected timeframe is Larger than chart timeframe, but not so large that too many bars would be necessary. Then the quotient is calculated by dividing the chosen timeframe (value in seconds) by the chart's timeframe (value in seconds).
Then take that quotient and multiply it by the chosen length. This gives us how many bars of the chart's timeframe would be used in calculating the higher timeframe Moving Average
Use the value to calculate a moving average of choice (SMA,EMA,WMA,LRC,DEMA,TEMA,TRIMA,FRAMA) thanks to @TradingView 's ta library (www.tradingview.com/script/BICzyhq0-ta/) and @alexgrover 's (www.tradingview.com/...ngth-PineCoders-FAQ/) for their functions supporting series as length, making this possible.

Basically, get how many of the current chart's bars are in the higher timeframe moving average and use that as the length for calculation using chart's timeframe.

If the higher timeframe relative is too large relative to chart's timeframe, due to bar referencing limits some combinations may not be possible under current limitations, but most will work by either moving chart's timeframe higher or higher timeframe lower assuming you aren't trying to do something too extreme like plotting a weekly moving average onto a 30 second chart etc.


Skrypt open-source

Zgodnie z prawdziwym duchem TradingView, autor tego skryptu opublikował go jako open-source, aby traderzy mogli go zrozumieć i zweryfikować. Brawo dla autora! Możesz używać go za darmo, ale ponowne wykorzystanie tego kodu w publikacji jest regulowane przez Dobre Praktyki. Możesz go oznaczyć jako ulubione, aby użyć go na wykresie.

Wyłączenie odpowiedzialności

Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.

Chcesz użyć tego skryptu na wykresie?