Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ Last but not least, `talipp` is a community project and therefore open to any su

### What's new in the recent versions

- Normalized Average True Range indicator
- Rogers-Satchell volatility indicator
- Williams %R indicator
- auto-sampling of input values

For the full history of changes see [Release Notes](https://github.com/nardew/talipp/releases).
Expand Down Expand Up @@ -86,6 +85,7 @@ For the full history of changes see [Release Notes](https://github.com/nardew/ta
- Ultimate Oscillator (UO)
- Vortex Indicator (VTX)
- Volume Weighted Average Price (VWAP)
- Williams %R
- ZigZag

### Installation
Expand Down
121 changes: 61 additions & 60 deletions docs/indicator-catalogue.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/binance_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
from cryptoxlib.version_conversions import async_run

from talipp.indicators import AccuDist, ADX, ALMA, AO, Aroon, ATR, BB, BOP, CCI, ChaikinOsc, ChandeKrollStop, CHOP, \
CoppockCurve, DEMA, DonchianChannels, DPO, EMA, EMV, ForceIndex, HMA, IBS, Ichimoku, \
KAMA, KeltnerChannels, KST, KVO, MACD, MassIndex, McGinleyDynamic, MeanDev, NATR, OBV, ROC, RogersSatchell, RSI, \
ParabolicSAR, \
SFX, SMA, SMMA, SOBV, STC, StdDev, \
Stoch, StochRSI, SuperTrend, T3, TEMA, TRIX, TSI, TTM, UO, VTX, VWAP, VWMA, WMA, ZigZag, ZLEMA
CoppockCurve, DEMA, DonchianChannels, DPO, EMA, EMV, ForceIndex, HMA, IBS, Ichimoku, KAMA, KeltnerChannels, KST, \
KVO, MACD, MassIndex, McGinleyDynamic, MeanDev, NATR, OBV, ROC, RogersSatchell, RSI, ParabolicSAR, SFX, SMA, SMMA, \
SOBV, STC, StdDev, Stoch, StochRSI, SuperTrend, T3, TEMA, TRIX, TSI, TTM, UO, VTX, VWAP, VWMA, Williams, WMA, \
ZigZag, ZLEMA
from talipp.ohlcv import OHLCV


Expand Down Expand Up @@ -85,6 +84,7 @@ async def run():
print(f'VTX: {VTX(14, ohlcv)[-1]}')
print(f'VWAP: {VWAP(ohlcv)[-1]}')
print(f'VWMA: {VWMA(20, ohlcv)[-1]}')
print(f'Williams: {Williams(14, ohlcv)[-5:]}')
print(f'WMA: {WMA(9, close)[-1]}')
print(f'ZigZag: {ZigZag(0.1, 4, ohlcv)[-15:]}')
print(f'ZLEMA: {ZLEMA(14, close)[-1]}')
Expand Down
3 changes: 2 additions & 1 deletion examples/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from talipp.indicators import AccuDist, ADX, ALMA, AO, Aroon, ATR, BB, BOP, CCI, ChaikinOsc, ChandeKrollStop, CHOP, \
CoppockCurve, DEMA, DonchianChannels, DPO, EMA, EMV, ForceIndex, HMA, IBS, Ichimoku, KAMA, KeltnerChannels, KST, KVO, \
MACD, MassIndex, MeanDev, NATR, OBV, ROC, RogersSatchell, RSI, ParabolicSAR, SFX, SMA, SMMA, SOBV, STC, StdDev, Stoch, StochRSI, \
SuperTrend, T3, TEMA, TRIX, TSI, TTM, UO, VTX, VWAP, VWMA, WMA, ZigZag, ZLEMA
SuperTrend, T3, TEMA, TRIX, TSI, TTM, UO, VTX, VWAP, VWMA, Williams, WMA, ZigZag, ZLEMA
from talipp.ohlcv import OHLCVFactory

if __name__ == "__main__":
Expand Down Expand Up @@ -71,6 +71,7 @@
print(f'VTX: {VTX(14, ohlcv)[-1]}')
print(f'VWAP: {VWAP(ohlcv)[-1]}')
print(f'VWMA: {VWMA(20, ohlcv)[-1]}')
print(f'Williams: {Williams(9, ohlcv)[-1]}')
print(f'WMA: {WMA(9, close)[-1]}')
print(f'ZigZag: {ZigZag(0.1, 10, ohlcv)[-5:]}')
print(f'ZLEMA: {ZLEMA(9, close)[-1]}')
54 changes: 54 additions & 0 deletions talipp/indicators/Williams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import List, Any

from talipp.indicator_util import has_valid_values
from talipp.indicators.Indicator import Indicator, InputModifierType
from talipp.input import SamplingPeriodType
from talipp.ohlcv import OHLCV


class Williams(Indicator):
"""Williams %R.

Input type: [OHLCV][talipp.ohlcv.OHLCV]

Output type: `float`

Args:
period: Period.
input_values: List of input values.
input_indicator: Input indicator.
input_modifier: Input modifier.
input_sampling: Input sampling type.
"""

def __init__(self, period: int,
input_values: List[OHLCV] = None,
input_indicator: Indicator = None,
input_modifier: InputModifierType = None,
input_sampling: SamplingPeriodType = None):
super().__init__(input_modifier=input_modifier,
input_sampling=input_sampling)

self.period = period

self.initialize(input_values, input_indicator)

def _calculate_new_value(self) -> Any:
if not has_valid_values(self.input_values, self.period):
return None

input_period = self.input_values[-1 * self.period:]

highs = [value.high for value in input_period if value.high is not None]
lows = [value.low for value in input_period if value.low is not None]

max_high = max(highs)
min_low = min(lows)

if max_high == min_low:
if has_valid_values(self.output_values, 1):
return self.output_values[-1]
else:
return None

return -100.0 * (max_high - self.input_values[-1].close) / (max_high - min_low)
2 changes: 2 additions & 0 deletions talipp/indicators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from .VTX import VTX as VTX
from .VWAP import VWAP as VWAP
from .VWMA import VWMA as VWMA
from .Williams import Williams as Williams
from .WMA import WMA as WMA
from .ZigZag import ZigZag as ZigZag
from .ZLEMA import ZLEMA as ZLEMA
Expand Down Expand Up @@ -115,6 +116,7 @@
"VTX",
"VWAP",
"VWMA",
"Williams",
"WMA",
"ZigZag",
"ZLEMA"
Expand Down
32 changes: 32 additions & 0 deletions test/test_Williams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest

from talipp.indicators import Williams

from TalippTest import TalippTest


class Test(TalippTest):
def setUp(self) -> None:
self.input_values = list(TalippTest.OHLCV_TMPL)

def test_init(self):
ind = Williams(14, self.input_values)

print(ind)

self.assertAlmostEqual(ind[-3], -11.065573, places = 5)
self.assertAlmostEqual(ind[-2], -25.819672, places = 5)
self.assertAlmostEqual(ind[-1], -35.245901, places = 5)

def test_update(self):
self.assertIndicatorUpdate(Williams(14, self.input_values))

def test_delete(self):
self.assertIndicatorDelete(Williams(14, self.input_values))

def test_purge_oldest(self):
self.assertIndicatorPurgeOldest(Williams(143, self.input_values))


if __name__ == '__main__':
unittest.main()
Loading