Created
March 15, 2025 14:29
-
-
Save miohtama/0d2b9bd692a4d69d1f79ae08ee4cce5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@indicators.define(dependencies=[ath, ath, daily_rsi]) | |
def signal( | |
close: pd.Series, | |
ath_delay_bars: int, | |
ath_window_bars: int, | |
ath_threshold: float, | |
ath_span: int, | |
daily_rsi_bars: int, | |
daily_rsi_threshold: float, | |
pair: TradingPairIdentifier, | |
dependency_resolver: IndicatorDependencyResolver | |
) -> pd.Series: | |
"""Combine ATH signal with daily RSI filter. | |
- We use daily RSI filter to get rid of crap pairs like FTC | |
""" | |
rsi = dependency_resolver.get_indicator_data( | |
"daily_rsi", | |
parameters={"daily_rsi_bars": daily_rsi_bars}, | |
pair=pair, | |
) | |
# Set default RSI value so we include pairs | |
# without enough history | |
rsi = rsi.fillna(50).infer_objects(copy=False) | |
ath = dependency_resolver.get_indicator_data( | |
"ath", | |
parameters={ | |
"ath_delay_bars": ath_delay_bars, | |
"ath_window_bars": ath_window_bars, | |
}, | |
pair=pair, | |
) | |
ath_core = ath.ewm(span=ath_span).mean() - ath_threshold | |
# Use daily RSI as a thrash filter | |
# See FTC: https://tradingstrategy.ai/trading-view/binance/pancakeswap-v2/ftc-usdt | |
df = pd.DataFrame({ | |
"rsi": rsi, | |
"ath_core": ath_core, | |
}) | |
# forward-fill from daily to hourly | |
# SHOULD handle forward fill until the live timestamp | |
df["rsi"] = df["rsi"].infer_objects(copy=False).ffill() | |
mask = df.rsi >= daily_rsi_threshold | |
df['ath_thresholded'] = 0.0 # Initialize with zeros | |
df.loc[mask, 'ath_thresholded'] = df.loc[mask, 'ath_core'] # Copy ATH indicator values from non-masked timestamps | |
return df["ath_thresholded"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment