Add script for generating Internal Bar Strength Band strategy signals
This commit is contained in:
parent
3573ad5ea6
commit
78be11ee9d
22
strategies/internal_bar_strength_band.py
Normal file
22
strategies/internal_bar_strength_band.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
def signals(data: pd.DataFrame) -> pd.Series:
|
||||||
|
"""
|
||||||
|
Calculate swing trading signals based on Internal Bar Strength Band strategy.
|
||||||
|
|
||||||
|
Returns a Series with 'L' for long signals and 'N' otherwise.
|
||||||
|
"""
|
||||||
|
ma_200 = data['Close'].rolling(window = 200).mean()
|
||||||
|
|
||||||
|
rolling_high_minus_low = (data['High'] - data['Low']).rolling(window = 25).mean()
|
||||||
|
rolling_high = data['High'].rolling(window = 10).max()
|
||||||
|
lower_band = rolling_high - 2.5 * rolling_high_minus_low
|
||||||
|
|
||||||
|
ibs = (data['Close'] - data['Low']) / (data['High'] - data['Low'])
|
||||||
|
|
||||||
|
signals = (
|
||||||
|
(data['Close'] > ma_200) &
|
||||||
|
(data['Close'] < lower_band) &
|
||||||
|
(ibs < 0.3)
|
||||||
|
).apply(lambda condition: 'L' if condition else 'N')
|
||||||
|
return signals
|
Loading…
Reference in New Issue
Block a user