Skip to content

Commit

Permalink
IBS (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
nardew authored Apr 5, 2024
1 parent 5c8ffd4 commit 1ea2007
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 59 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html

## [Pending release]

## [2.2.0] - 2024-04-05

- new `IBS` indicator

## [2.1.2] - 2024-04-01

- fix `Aroon` indicator arguments
Expand Down Expand Up @@ -96,7 +100,8 @@ The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html

- the official release of `talipp`

[Pending release]: https://github.com/nardew/talipp/compare/2.1.2...HEAD
[Pending release]: https://github.com/nardew/talipp/compare/2.2.0...HEAD
[2.2.0]: https://github.com/nardew/talipp/releases/tag/2.2.0
[2.1.2]: https://github.com/nardew/talipp/releases/tag/2.1.2
[2.1.1]: https://github.com/nardew/talipp/compare/2.1.0...2.1.1
[2.1.0]: https://github.com/nardew/talipp/compare/2.0.0...2.1.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Last but not least, `talipp` is a community project and therefore open to any su

### What's new in the latest version

- IBS indicator
- auto-sampling of input values

- [v2.0.0 scope](https://github.com/nardew/talipp/issues/111)
Expand Down Expand Up @@ -61,6 +62,7 @@ For the full history of changes see [CHANGELOG](https://github.com/nardew/talipp
- Detrended Price Oscillator (DPO)
- Ease of Movement (EMV)
- Force Index
- IBS
- Ichimoku Kinko Hyo
- Keltner Channel (KC)
- Klinger Volume Oscillator (KVO)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.2
2.2.0
111 changes: 56 additions & 55 deletions docs/indicator-catalogue.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/binance_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from cryptoxlib.Pair import Pair
from cryptoxlib.clients.binance import enums
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, Ichimoku, \
CoppockCurve, DEMA, DonchianChannels, DPO, EMA, EMV, ForceIndex, HMA, IBS, Ichimoku, \
KAMA, KeltnerChannels, KST, KVO, MACD, MassIndex, McGinleyDynamic, MeanDev, OBV, PivotsHL, ROC, RSI, ParabolicSAR, \
SFX, SMA, SMMA, SOBV, STC, StdDev, \
Stoch, StochRSI, SuperTrend, T3, TEMA, TRIX, TSI, TTM, UO, VTX, VWAP, VWMA, WMA, ZLEMA
Expand Down Expand Up @@ -49,6 +50,7 @@ async def run():
print(f'EMV: {EMV(14, 10000, ohlcv)[-1]}')
print(f'ForceIndex: {ForceIndex(13, ohlcv)[-1]}')
print(f'HMA: {HMA(9, close)[-1]}')
print(f'IBS: {IBS(ohlcv)[-5:]}')
print(f'Ichimoku: {Ichimoku(26, 9, 52, 52, 26, ohlcv)[-1]}')
print(f'KAMA: {KAMA(14, 2, 30, close)[-1]}')
print(f'KeltnerChannels: {KeltnerChannels(20, 26, 1, 1, ohlcv)[-1]}')
Expand Down
3 changes: 2 additions & 1 deletion examples/indicators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random

from talipp.indicators import AccuDist, ADX, ALMA, AO, Aroon, ATR, BB, BOP, CCI, ChaikinOsc, ChandeKrollStop, CHOP, \
CoppockCurve, DEMA, DonchianChannels, DPO, EMA, EMV, ForceIndex, HMA, Ichimoku, KAMA, KeltnerChannels, KST, KVO, \
CoppockCurve, DEMA, DonchianChannels, DPO, EMA, EMV, ForceIndex, HMA, IBS, Ichimoku, KAMA, KeltnerChannels, KST, KVO, \
MACD, MassIndex, MeanDev, OBV, PivotsHL, ROC, RSI, ParabolicSAR, SFX, SMA, SMMA, SOBV, STC, StdDev, Stoch, StochRSI, \
SuperTrend, T3, TEMA, TRIX, TSI, TTM, UO, VTX, VWAP, VWMA, WMA, ZLEMA
from talipp.ohlcv import OHLCVFactory
Expand Down Expand Up @@ -38,6 +38,7 @@
print(f'EMV: {EMV(14, 10000, ohlcv)[-1]}')
print(f'ForceIndex: {ForceIndex(13, ohlcv)[-1]}')
print(f'HMA: {HMA(9, close)[-1]}')
print(f'IBS: {IBS(ohlcv)[-1]}')
print(f'Ichimoku: {Ichimoku(26, 9, 52, 52, 26, ohlcv)[-1]}')
print(f'KAMA: {KAMA(14, 2, 30, close)[-1]}')
print(f'KeltnerChannels: {KeltnerChannels(20, 26, 1, 1, ohlcv)[-1]}')
Expand Down
38 changes: 38 additions & 0 deletions talipp/indicators/IBS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 IBS(Indicator):
"""Internal Bar Strength.
Input type: [OHLCV][talipp.ohlcv.OHLCV]`
Output type: `float`
Args:
input_values: List of input values.
input_indicator: Input indicator.
input_modifier: Input modifier.
input_sampling: Input sampling type.
"""

def __init__(self,
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.initialize(input_values, input_indicator)

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

candle: OHLCV = self.input_values[-1]
return (candle.close - candle.low) / (candle.high - candle.low)
2 changes: 2 additions & 0 deletions talipp/indicators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .FibRetracement import FibRetracement as FibRetracement
from .ForceIndex import ForceIndex as ForceIndex
from .HMA import HMA as HMA
from .IBS import IBS as IBS
from .Ichimoku import Ichimoku as Ichimoku
from .KAMA import KAMA as KAMA
from .KeltnerChannels import KeltnerChannels as KeltnerChannels
Expand Down Expand Up @@ -76,6 +77,7 @@
"FibRetracement",
"ForceIndex",
"HMA",
"IBS",
"Ichimoku",
"KAMA",
"KeltnerChannels",
Expand Down
32 changes: 32 additions & 0 deletions test/test_IBS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest

from talipp.indicators import IBS

from TalippTest import TalippTest


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

def test_init(self):
ind = IBS(self.input_values)

print(ind)

self.assertAlmostEqual(ind[-3], 0.597014, places = 5)
self.assertAlmostEqual(ind[-2], 0.129032, places = 5)
self.assertAlmostEqual(ind[-1], 0.493506, places = 5)

def test_update(self):
self.assertIndicatorUpdate(IBS(self.input_values))

def test_delete(self):
self.assertIndicatorDelete(IBS(self.input_values))

def test_purge_oldest(self):
self.assertIndicatorPurgeOldest(IBS(self.input_values))


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

0 comments on commit 1ea2007

Please sign in to comment.