talipp icon indicating copy to clipboard operation
talipp copied to clipboard

Wilder's Moving Average

Open femtotrader opened this issue 1 year ago • 4 comments

Hello,

See https://www.incrediblecharts.com/indicators/wilder_moving_average.php

A number of popular indicators, including Relative Strength Index (RSI), Average True Range (ATR) and Directional Movement were developed by J. Welles Wilder and introduced in his 1978 book: New Concepts in Technical Trading Systems. Users should beware that Wilder does not use the standard exponential moving average formula.

Do we have WilderMA in talipp ? (not to be confused with WeightedMA)

Kind regards

PS: see also https://www.tradingview.com/script/wXtQeoOg/#:~:text=Wilder%20did%20not%20use%20the,where%20K%20%3D1%2FN.

femtotrader avatar Jul 08 '24 12:07 femtotrader

Looking at

https://github.com/nardew/talipp/blob/ed5e0e10c986121b5762d4538649212ec05a9847/talipp/indicators/ATR.py#L58

$$output_{i} = \frac{output_{i-1} \cdot (period - 1) + TR_{i - 1}}{period}$$

with $k = \frac{1}{period}$

we have

$$output_{i} = output_{i-1} \cdot \frac{(period - 1)}{period} + \frac{1}{period} \cdot TR_{i - 1}$$

which is also

$$output_{i} = output_{i-1} \cdot (1 - \frac{1}{period}) + \frac{1}{period} \cdot TR_{i - 1}$$

and so

$$output_{i} = output_{i-1} \cdot (1 - k) + k \cdot TR_{i - 1}$$

So we can say that current talipp implementation at ATR is using Wilder's Moving Average for smoothing true range (which is fine!)

Maybe we could define such a MA in talipp and give user opportunity to use it's own MA for ATR calculation?

femtotrader avatar Jul 08 '24 13:07 femtotrader

Maybe we should have an indicator called simply TrueRange which simply computes True Range of incoming bars and use a smoother as exposed in #146 to build ATR with Wilder's Moving Average.

femtotrader avatar Jul 08 '24 13:07 femtotrader

This would simplify CHOP code which currently uses ATR(1) but will use instead just TrueRange() (because with period=1, k=1 and so

$$output_i = output_{i-1} \cdot (1 - 1) + 1 \cdot TR_{i - 1} $$

$$output_i = TR_{i-1}$$

femtotrader avatar Jul 08 '24 13:07 femtotrader

Wilder's MA and SMMA seems to be the exact same thing.

This code https://github.com/nardew/talipp/blob/main/talipp/indicators/ATR.py#L53-L58 and https://github.com/nardew/talipp/blob/main/talipp/indicators/SMMA.py#L34-L40 could probably be refactored to use in ATR calculation SMMA

femtotrader avatar Nov 08 '24 18:11 femtotrader