Files
trading_bot_v4/backtester/math_utils.py
mindesbunister 5f7702469e remove: V10 momentum system - backtest proved it adds no value
- Removed v10 TradingView indicator (moneyline_v10_momentum_dots.pinescript)
- Removed v10 penalty system from signal-quality.ts (-30/-25 point penalties)
- Removed backtest result files (sweep_*.csv)
- Updated copilot-instructions.md to remove v10 references
- Simplified direction-specific quality thresholds (LONG 90+, SHORT 80+)

Rationale:
- 1,944 parameter combinations tested in backtest
- All top results IDENTICAL (568 trades, $498 P&L, 61.09% WR)
- Momentum parameters had ZERO impact on trade selection
- Profit factor 1.027 too low (barely profitable after fees)
- Max drawdown -$1,270 vs +$498 profit = terrible risk-reward
- v10 penalties were blocking good trades (bug: applied to wrong positions)

Keeping v9 as production system - simpler, proven, effective.
2025-11-28 22:35:32 +01:00

47 lines
1.5 KiB
Python

from __future__ import annotations
import numpy as np
import pandas as pd
def rma(series: pd.Series, length: int) -> pd.Series:
alpha = 1.0 / length
result = series.astype(float).copy()
for i in range(1, len(series)):
prev = result.iat[i - 1]
curr = series.iat[i]
result.iat[i] = alpha * curr + (1 - alpha) * prev
return result
def calculate_atr(df: pd.DataFrame, length: int) -> pd.Series:
high, low, close = df["high"], df["low"], df["close"]
tr = pd.concat([
(high - low),
(high - close.shift(1)).abs(),
(low - close.shift(1)).abs(),
], axis=1).max(axis=1)
tr.iloc[0] = (high.iloc[0] - low.iloc[0])
return rma(tr, length)
def calculate_adx(df: pd.DataFrame, length: int) -> pd.Series:
high, low, close = df["high"], df["low"], df["close"]
up_move = high.diff()
down_move = -low.diff()
plus_dm = np.where((up_move > down_move) & (up_move > 0), up_move, 0.0)
minus_dm = np.where((down_move > up_move) & (down_move > 0), down_move, 0.0)
tr = pd.concat([
(high - low),
(high - close.shift(1)).abs(),
(low - close.shift(1)).abs(),
], axis=1).max(axis=1)
tr.iloc[0] = (high.iloc[0] - low.iloc[0])
atr = rma(tr, length)
plus_di = 100.0 * rma(pd.Series(plus_dm), length) / atr
minus_di = 100.0 * rma(pd.Series(minus_dm), length) / atr
dx = 100.0 * (plus_di - minus_di).abs() / (plus_di + minus_di).replace(0, np.nan)
dx = dx.fillna(0.0)
return rma(dx, length)