mirror of
https://github.com/silencesdg/mt5_python_ea_suite.git
synced 2026-08-21 06:38:14 +00:00
add ml
This commit is contained in:
@@ -38,13 +38,16 @@ class DailyBreakoutStrategy(BaseStrategy):
|
||||
|
||||
def run_backtest(self, df):
|
||||
df = df.copy()
|
||||
df['time'] = pd.to_datetime(df['time'], unit='s')
|
||||
df['date'] = df['time'].dt.date
|
||||
# BUG FIX: The 'time' column does not exist in a properly formed dataframe.
|
||||
# Time information should be derived from the DatetimeIndex.
|
||||
df['date'] = df.index.date
|
||||
|
||||
# LOGIC FIX: daily_lows should be the minimum of the day, not the maximum.
|
||||
daily_highs = df.groupby('date')['high'].transform('max')
|
||||
daily_lows = df.groupby('date')['low'].transform('max')
|
||||
daily_lows = df.groupby('date')['low'].transform('min')
|
||||
|
||||
signals = pd.Series(0, index=df.index)
|
||||
# Signal when close breaks yesterday's high/low
|
||||
signals[df['close'] > daily_highs.shift(1)] = 1
|
||||
signals[df['close'] < daily_lows.shift(1)] = -1
|
||||
return signals
|
||||
Reference in New Issue
Block a user