Fix weekend gap risk and short signal detection

Grid EA (v3.1):
- Add weekend protection: close positions Friday before market close
- New settings: InpCloseBeforeWeekend, InpWeekendCloseHour, InpCancelPendingBeforeWeekend
- Prevents gap risk when market reopens Sunday/Monday
- FIX: Restore missing #include statements

Confluence EA (v1.14):
- Fix short signal detection by removing restrictive 'belowPivot' check
- Mirror BUY and SELL logic for symmetry
- Relax harmonic pattern tolerances (0.3-1.0 vs 0.5-0.8)
- Short signals now match buy signal generation

Add verify-short-signals.py to test short signal generation
This commit is contained in:
2026-03-29 23:40:59 -04:00
parent ac32303eeb
commit c53dff6d9f
3 changed files with 221 additions and 61 deletions

View File

@@ -5,13 +5,12 @@
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, Garfield Heron"
#property link "https://fetcherpay.com"
#property version "3.0"
#property strict
#property version "3.1"
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#define VERSION "Version 3.0 Smart Grid MT5"
#define VERSION "Version 3.1 Smart Grid MT5"
#define MAX_TRADES 600
#define MAX_LOG_TRADES 1200
@@ -60,6 +59,12 @@ input bool Master= false;
input bool DiagnosticModeOn= false;
input double InpMaxDailyDrawdown = 3.0; // Max daily drawdown % (0=disable)
//--- Weekend Protection
input string WeekendSettings = "=== Weekend Protection ===";
input bool InpCloseBeforeWeekend = true; // Close positions Friday before market close
input int InpWeekendCloseHour = 17; // Hour to close (17 = 5 PM broker time)
input bool InpCancelPendingBeforeWeekend = true; // Cancel pending orders too
//--- Trade Object
CTrade trade;
CPositionInfo positionInfo;
@@ -123,6 +128,10 @@ bool S1HitToday = false;
double dailyStartEquity = 0;
datetime lastEquityReset = 0;
//--- Weekend Protection Variables
bool weekendCloseExecuted = false;
datetime lastWeekendCheck = 0;
//+------------------------------------------------------------------+
//| Check Daily Drawdown Protection |
//+------------------------------------------------------------------+
@@ -169,7 +178,50 @@ bool CheckDailyDrawdown()
}
return true;
}
}
//+------------------------------------------------------------------+
//| Check Weekend Protection |
//+------------------------------------------------------------------+
bool CheckWeekendProtection()
{
if(!InpCloseBeforeWeekend) return true;
MqlDateTime dt;
TimeToStruct(TimeCurrent(), dt);
// Only check on Friday
if(dt.day_of_week != FRIDAY)
{
// Reset flag on other days
if(weekendCloseExecuted)
weekendCloseExecuted = false;
return true;
}
// Already executed this Friday
if(weekendCloseExecuted) return true;
// Check if it's close to weekend close time
if(dt.hour >= InpWeekendCloseHour)
{
Print("⚠️ WEEKEND CLOSE: It's Friday ", dt.hour, ":00 - Closing all positions!");
SendNotificationEx("WEEKEND CLOSE", "Closing all positions before weekend");
// Close all open positions
CloseAllPositions("Weekend protection - Friday close");
// Cancel pending orders if enabled
if(InpCancelPendingBeforeWeekend)
CancelAllOrders("Weekend protection - Friday cancel pending");
weekendCloseExecuted = true;
gridPlaced = false;
return false;
}
return true;
}
//+------------------------------------------------------------------+
//| Calculate Pivot Points |
@@ -614,15 +666,19 @@ void OnTick()
// Check daily drawdown limit
if(!CheckDailyDrawdown())
{
// Drawdown limit reached - don't place new grids
if(gridPlaced)
{
Print("Daily drawdown limit reached - not placing new grids");
gridPlaced = false;
}
{
// Drawdown limit reached - don't place new grids
if(gridPlaced)
{
Print("Daily drawdown limit reached - not placing new grids");
gridPlaced = false;
}
return;
}
// Check weekend protection (close Friday before weekend)
if(!CheckWeekendProtection())
return;
}
// Recalculate pivots at new day (hour 0, first 5 minutes)
// Only cancel PENDING orders, let positions run to SL/TP