Update app.py
Browse files
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
|
57 |
-
buyThreshold =
|
58 |
-
sellThreshold = -
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|