ApopheniaPays

Demonstration of how history length affects all EMA values

I saw some discussion of this so I whipped up an example to prove the that effect of history length on EMA values is pronounced, even for bars much further than the EMA length from the first candle of the chart.

This chart has two 89-bar EMAs of the close: a green one and a red one. However, for the red one, the first 89 bars of the graph are considered to have a close of "0", which is exactly whatTradingView's EMA calculation uses for bars before the start of the graph.

This is because unlike other moving averages, which reference the price of previous bars, the EMA references the EMA of previous bars. Therefore, bars closer to the beginning of the chart, where TradingView can't calculate an EMA because there is no previous EMA and therefore uses 0, will return substantially different values for the EMA() function that the same cart would with more history.

The further a bar is back in history, the less influence it has. However, every single historical bar has some influence on the EMA of every later bar.

To allow you to see this for yourself, this script contains the following inputs which you can change to see the effect:
-EMA period (default 89)
-Number of bars to ignore for EMA2 (default 89)
-decimal precision to show differences in. By making this a large number you can see that, although the effects diminish, history length affects all EMA values for the char.
-label spacing (increase this if you have a long history and run into TV's 50-label limit)
Release Notes:
-Corrected error where ignored bars at beginning were still based on EMA length rather than input value
-Added bar labels to indicate integer multiples of EMA length

apop@apopheniapays.com
Twitter/TradingView: ApopheniaPays
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?