nardew / talipp

talipp - incremental technical analysis library for python
https://nardew.github.io/talipp
MIT License
386 stars 60 forks source link

Wilder's Moving Average #150

Open femtotrader opened 3 months ago

femtotrader commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

$$outputi = output{i-1} \cdot (1 - 1) + 1 \cdot TR_{i - 1} $$

$$outputi = TR{i-1}$$