feat: Add trading logic for BB, RSI, and EMA indicators in strategy
This commit is contained in:
parent
a18bc66b19
commit
e48fcfafbd
@ -69,7 +69,6 @@ class DynamicStrategy(Strategy):
|
||||
self.indicators[f"{ind_name}_lower"] = bb_vals[2]
|
||||
|
||||
def next(self):
|
||||
# Simple example strategy - should be customized based on user input
|
||||
price = self.data.Close[-1]
|
||||
|
||||
# Example trading logic using indicators
|
||||
@ -90,6 +89,33 @@ class DynamicStrategy(Strategy):
|
||||
self.buy()
|
||||
elif macd < signal and prev_macd >= prev_signal and self.position:
|
||||
self.position.close()
|
||||
|
||||
elif ind_config['type'] == 'BB':
|
||||
upper = self.indicators[f"{ind_name}_upper"][-1]
|
||||
lower = self.indicators[f"{ind_name}_lower"][-1]
|
||||
|
||||
# Buy when price touches lower band
|
||||
if price <= lower and not self.position:
|
||||
self.buy()
|
||||
# Sell when price touches upper band
|
||||
elif price >= upper and self.position:
|
||||
self.position.close()
|
||||
|
||||
elif ind_config['type'] == 'RSI':
|
||||
rsi = self.indicators[ind_name][-1]
|
||||
|
||||
# Buy when RSI is below 30 (oversold)
|
||||
if rsi < 30 and not self.position:
|
||||
self.buy()
|
||||
# Sell when RSI is above 70 (overbought)
|
||||
elif rsi > 70 and self.position:
|
||||
self.position.close()
|
||||
|
||||
elif ind_config['type'] == 'EMA':
|
||||
if price > self.indicators[ind_name][-1] and not self.position:
|
||||
self.buy()
|
||||
elif price < self.indicators[ind_name][-1] and self.position:
|
||||
self.position.close()
|
||||
|
||||
def get_available_indicators() -> Dict:
|
||||
"""Returns available indicators and their parameters"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user