riteshcp commited on
Commit
97600c5
·
verified ·
1 Parent(s): 2806161

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -44,7 +44,7 @@ def calculate_indicators(df, lengthEMA=3, lengthRSI=14, momentumLength=3, trendL
44
  # Calculate Momentum
45
  df['Momentum'] = df['Close'].diff(momentumLength)
46
 
47
- # Composite SIGNAL Calculation
48
  df['SignalComposite'] = (0.5 * df['SignalEMA']) + (0.3 * (df['RSI'] - 50) / 100) + (0.2 * (df['Momentum'] / df['Close'].rolling(window=lengthRSI).mean()))
49
 
50
  # Smooth the Composite SIGNAL with EMA
@@ -53,11 +53,17 @@ def calculate_indicators(df, lengthEMA=3, lengthRSI=14, momentumLength=3, trendL
53
  # Trend Filter (SMA)
54
  df['TrendSMA'] = df['Close'].rolling(window=trendLength).mean()
55
 
56
- # Buy and Sell Signals
57
- buyThreshold = 0.75
58
- sellThreshold = -0.75
59
- df['BuySignal'] = (df['SmoothedSignal'] > buyThreshold) & (df['Close'] > df['TrendSMA'])
60
- df['SellSignal'] = (df['SmoothedSignal'] < sellThreshold) & (df['Close'] < df['TrendSMA'])
 
 
 
 
 
 
61
 
62
  return df
63
 
 
44
  # Calculate Momentum
45
  df['Momentum'] = df['Close'].diff(momentumLength)
46
 
47
+ # Composite SIGNAL Calculation with Dynamic Adjustments
48
  df['SignalComposite'] = (0.5 * df['SignalEMA']) + (0.3 * (df['RSI'] - 50) / 100) + (0.2 * (df['Momentum'] / df['Close'].rolling(window=lengthRSI).mean()))
49
 
50
  # Smooth the Composite SIGNAL with EMA
 
53
  # Trend Filter (SMA)
54
  df['TrendSMA'] = df['Close'].rolling(window=trendLength).mean()
55
 
56
+ # Adjusted Buy and Sell Thresholds
57
+ buyThreshold = 1.5 # Increased threshold for stronger signals
58
+ sellThreshold = -1.5
59
+
60
+ # Buy and Sell Signals with Momentum Condition
61
+ df['BuySignal'] = (df['SmoothedSignal'] > buyThreshold) & (df['Close'] > df['TrendSMA']) & (df['Momentum'] > 0)
62
+ df['SellSignal'] = (df['SmoothedSignal'] < sellThreshold) & (df['Close'] < df['TrendSMA']) & (df['Momentum'] < 0)
63
+
64
+ # Add Cooldown Logic to Reduce Repeated Signals
65
+ df['BuySignal'] = df['BuySignal'] & ~df['BuySignal'].shift(1).fillna(False)
66
+ df['SellSignal'] = df['SellSignal'] & ~df['SellSignal'].shift(1).fillna(False)
67
 
68
  return df
69