JayLacoma commited on
Commit
66d84a0
·
verified ·
1 Parent(s): 00def51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -30
app.py CHANGED
@@ -45,13 +45,7 @@ def calculate_stochastic_oscillator(df):
45
  slowd = slowk.rolling(window=3).mean()
46
  return slowk, slowd
47
 
48
- def calculate_atr(df, window=14):
49
- high_low = df['High'] - df['Low']
50
- high_close = np.abs(df['High'] - df['Close'].shift())
51
- low_close = np.abs(df['Low'] - df['Close'].shift())
52
- tr = high_low.combine(high_close, max).combine(low_close, max)
53
- atr = tr.rolling(window=window).mean()
54
- return atr
55
 
56
  def calculate_cmf(df, window=20):
57
  mfv = ((df['Close'] - df['Low']) - (df['High'] - df['Close'])) / (df['High'] - df['Low']) * df['Volume']
@@ -66,29 +60,6 @@ def calculate_cci(df, window=20):
66
  cci = (typical_price - sma) / (0.015 * mean_deviation)
67
  return cci
68
 
69
- def calculate_atr_signal(df, atr_column='ATR', close_column='Close', atr_window=20, ma_window=50, volatility_days=3, atr_threshold=1.2):
70
-
71
- # Calculate the 20-day ATR rolling mean and high volatility threshold
72
- df['ATR_20'] = df[atr_column].rolling(window=atr_window).mean()
73
- df['High_Volatility'] = np.where(df[atr_column] > atr_threshold * df['ATR_20'], 1, 0)
74
-
75
- # Calculate the 50-day moving average of the close prices for trend direction
76
- df['MA_50'] = df[close_column].rolling(window=ma_window).mean()
77
-
78
- # Generate the ATR signal based on high volatility and trend direction
79
- df['ATR_Signal'] = np.where(
80
- (df['High_Volatility'].rolling(window=volatility_days).sum() >= volatility_days) & (df[close_column] > df['MA_50']),
81
- 1, # Buy Signal
82
- np.where(
83
- (df['High_Volatility'].rolling(window=volatility_days).sum() >= volatility_days) & (df[close_column] < df['MA_50']),
84
- -1, # Sell Signal
85
- 0 # No Signal
86
- )
87
- )
88
-
89
- # Return only the ATR_Signal column as output
90
- return df['ATR_Signal']
91
-
92
 
93
 
94
  def generate_trading_signals(df):
 
45
  slowd = slowk.rolling(window=3).mean()
46
  return slowk, slowd
47
 
48
+
 
 
 
 
 
 
49
 
50
  def calculate_cmf(df, window=20):
51
  mfv = ((df['Close'] - df['Low']) - (df['High'] - df['Close'])) / (df['High'] - df['Low']) * df['Volume']
 
60
  cci = (typical_price - sma) / (0.015 * mean_deviation)
61
  return cci
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
 
65
  def generate_trading_signals(df):