OPEN-SOURCE SCRIPT

Forward Backward EMA [Repaint]

Perform forward-backward filtering using exponential averaging, thus providing a zero-phase exponential moving average. The output repaint and cannot be used as input for other indicators.

Settings

  • Length : moving average period
  • Src : data input of the moving average
  • Plot Color : the color of the displayed plot
  • Line Width : width of the plotted line


Usages

The main usage of moving averages is to provide an estimate of the underlying trend in the price by removing higher term variations from it. Non-causal (repainting) indicators are limited to offline applications, as such, they are most useful for summary analyses, note that it is still possible to infer from the output of repainting indicators, however since past outputs are subject to changes, it is extremely difficult to track the effectiveness of such indicators, and in online applications they only track the price, making them equally useful for predictive applications than following the direction of an individual candle.

스냅샷

Non-causal filters can be useful in order to have a better view of symbols with a relatively uninformative evolution.

Details

Causal filters have lag, this is the cost of using past observations as inputs, the more past observations you use, the more lag you will obtain (assuming these past observations have non-zero weights). There are various solutions to reduce the lag of a moving average, the most simple one relying on giving higher weights to more recent observations, another one relies on introducing gain in the filter passband, that is amplifying certain variations in the input signal while attenuating/removing higher term ones, finally, we can use adaptive moving averages to avoid excessive lag.

All these previous solutions can be used causally, but they are far from being perfect, as the lag reduction is often done at the cost of smoothness, if we were to keep the original smoothness of the filter while having no lag we would need to use non-causal solutions. The most common solution is to directly use future values as inputs, such moving averages are called "two-sided" moving averages since they use past values as input (left side) as well as future input values (right side), this is equivalent to shifting the results of a moving average backward.

The advantages of two-sided moving averages is that they conserve the original amplitude response of the moving average, however, it won't be possible to compute the most recent values of the moving average (since we won't have access to future values at a certain point), an alternative method heavily used in digital signal processing is forward-backward filtering.

The method consists of applying a filter forward in time, then we apply it once again backward. In order for you to have an easier understanding of this process think about applying a moving average normally starting at time t = 0, then apply that moving average once again using the previous results as input but start from t = N-1, that is from the most recent point, and proceed backward, plotting the result from left to right until you get back to t = 0.

From this, it follows that forward-backward filtering applies a filter twice, the resulting filter is thus a two-passes filter, this results in an even smoother output (more precisely the filter amplitude response is squared).

Forward-backward filtering can be done in Pinescript by using the function "line.new" inside a loop, an exponential moving average is applied forward first, then once again backward inside the loop, "line.new" is used to plot the results backward.

Notes

It is important to note that forward-backward filtering is a repainting process, all the results of the indicator you see on the chart are subject to change over time. Since the method make use of line.new you will have around only 54 visible observations, with the impossibility of using them as input for other indicators. If you see indicators in the future with the same characteristics be aware that they will repaint.

Never purchase/rent filters that appear as having no lag, they are either repainting or the results are coming from a lucky shot or from an overfitted model, it is impossible to make both zero-lag and causal moving averages with pinescript, if you have doubt don't test your luck, better safe than sorry.





exponentialmovingaveragesforwardbackwardMoving AveragesrepaintTrend Analysiszerolagzerophase

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?


Check out the indicators we are making at luxalgo: tradingview.com/u/LuxAlgo/
또한 다음에서도:

면책사항