Prepare source-only public release for develop.
Add cluster audit pipeline, united EA updates, brochure generators, and publication hygiene (gitignore, MT5 path desensitization, pre-upload scan). Remove tracked reports, models, and binary artifacts from the repo. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
3f75a08848
commit
605faf5310
@@ -10,13 +10,14 @@ import pandas as pd
|
||||
|
||||
|
||||
def calculate_rsi(prices: pd.Series, period: int = 14) -> pd.Series:
|
||||
"""Calculate RSI indicator."""
|
||||
"""Calculate RSI with Wilder smoothing (matches MT5 iRSI)."""
|
||||
delta = prices.diff()
|
||||
gain = (delta.where(delta > 0, 0)).rolling(window=period).mean()
|
||||
loss = (-delta.where(delta < 0, 0)).rolling(window=period).mean()
|
||||
rs = gain / loss
|
||||
rsi = 100 - (100 / (1 + rs))
|
||||
return rsi
|
||||
gain = delta.clip(lower=0)
|
||||
loss = (-delta).clip(lower=0)
|
||||
avg_gain = gain.ewm(alpha=1 / period, adjust=False).mean()
|
||||
avg_loss = loss.ewm(alpha=1 / period, adjust=False).mean()
|
||||
rs = avg_gain / avg_loss.replace(0, np.nan)
|
||||
return 100 - (100 / (1 + rs))
|
||||
|
||||
|
||||
def calculate_ema(prices: pd.Series, period: int = 50) -> pd.Series:
|
||||
@@ -30,13 +31,35 @@ def calculate_sma(prices: pd.Series, period: int = 50) -> pd.Series:
|
||||
|
||||
|
||||
def calculate_atr(df: pd.DataFrame, period: int = 14) -> pd.Series:
|
||||
"""Calculate ATR indicator."""
|
||||
"""Calculate ATR with Wilder smoothing (matches MT5 iATR)."""
|
||||
high_low = df['high'] - df['low']
|
||||
high_close = np.abs(df['high'] - df['close'].shift())
|
||||
low_close = np.abs(df['low'] - df['close'].shift())
|
||||
tr = pd.concat([high_low, high_close, low_close], axis=1).max(axis=1)
|
||||
atr = tr.rolling(window=period).mean()
|
||||
return atr
|
||||
return tr.ewm(alpha=1 / period, adjust=False).mean()
|
||||
|
||||
|
||||
def calculate_adx(df: pd.DataFrame, period: int = 14) -> pd.Series:
|
||||
"""Calculate ADX indicator (Wilder smoothing)."""
|
||||
return calculate_dmi(df, period)["adx"]
|
||||
|
||||
|
||||
def calculate_dmi(df: pd.DataFrame, period: int = 14) -> pd.DataFrame:
|
||||
"""Calculate +DI, -DI, and ADX."""
|
||||
high = df["high"]
|
||||
low = df["low"]
|
||||
close = df["close"]
|
||||
up = high.diff()
|
||||
down = -low.diff()
|
||||
plus_dm = up.where((up > down) & (up > 0), 0.0)
|
||||
minus_dm = down.where((down > up) & (down > 0), 0.0)
|
||||
tr = pd.concat([high - low, (high - close.shift()).abs(), (low - close.shift()).abs()], axis=1).max(axis=1)
|
||||
atr = tr.ewm(alpha=1 / period, adjust=False).mean()
|
||||
plus_di = 100 * (plus_dm.ewm(alpha=1 / period, adjust=False).mean() / atr.replace(0, np.nan))
|
||||
minus_di = 100 * (minus_dm.ewm(alpha=1 / period, adjust=False).mean() / atr.replace(0, np.nan))
|
||||
dx = 100 * (plus_di - minus_di).abs() / (plus_di + minus_di).replace(0, np.nan)
|
||||
adx = dx.ewm(alpha=1 / period, adjust=False).mean()
|
||||
return pd.DataFrame({"plus_di": plus_di, "minus_di": minus_di, "adx": adx})
|
||||
|
||||
|
||||
def calculate_macd(prices: pd.Series, fast: int = 12, slow: int = 26, signal: int = 9) -> pd.DataFrame:
|
||||
|
||||
Reference in New Issue
Block a user