Files
Bell-PriceActionWithEma-EA/Experts/EA_ICT_CL.mq5
T

118 lines
4.2 KiB
Plaintext
Raw Normal View History

2026-03-06 22:38:09 +07:00
//+------------------------------------------------------------------+
//| ICT EA FVG Edition (MQL5) v4.3 |
2026-03-10 22:21:59 +07:00
//| Architecture : MiddleTF(H1) + TriggerTF(M5) |
2026-03-08 05:18:56 +07:00
//| State Machine: IDLE → WAIT_TOUCH → WAIT_TRIGGER → IN_TRADE |
2026-03-08 01:09:31 +07:00
//| |
//| Flow tổng thể: |
2026-03-10 22:21:59 +07:00
//| 1. H1 trend xác định hướng, tìm FVG thuận xu hướng |
//| 2. Giá touch H1 FVG → chờ M5 MSS xác nhận |
//| 3. M5 MSS = swing break thuận chiều H1: |
//| - H1 UP → close > tH0 (phá swing high) = bull MSS |
//| - H1 DOWN → close < tL0 (phá swing low) = bear MSS |
2026-03-10 22:21:59 +07:00
//| 4. Entry = limit tại swing level vừa bị phá (tH0 hoặc tL0) |
//| 5. SL = swing đối diện (tL0 cho buy, tH0 cho sell) |
//| 6. TP = Entry ± 2R |
2026-03-06 22:38:09 +07:00
//+------------------------------------------------------------------+
2026-03-10 20:51:27 +07:00
#property copyright "Bell's ICT EA"
#property version "4.30"
2026-03-06 22:38:09 +07:00
2026-03-10 23:43:41 +07:00
#define MAX_FVG_POOL 30
#define MAX_ORDER_HISTORY 50
#define ORDER_HIST_DAYS 3
2026-03-08 05:18:56 +07:00
2026-03-10 20:51:27 +07:00
#include "EA_ICT_CL/Config.mqh"
#include "EA_ICT_CL/State.mqh"
2026-03-06 22:38:09 +07:00
2026-03-10 20:51:27 +07:00
#include "EA_ICT_CL/Utils.mqh"
#include "EA_ICT_CL/Logging.mqh"
#include "EA_ICT_CL/Market.mqh"
#include "EA_ICT_CL/Indicators.mqh"
#include "EA_ICT_CL/Sessions.mqh"
#include "EA_ICT_CL/Filters.mqh"
#include "EA_ICT_CL/Risk.mqh"
#include "EA_ICT_CL/Orders.mqh"
#include "EA_ICT_CL/Swing.mqh"
#include "EA_ICT_CL/Trailing.mqh"
2026-03-10 20:51:27 +07:00
EAState g_State = EA_IDLE;
BlockReason g_BlockReason = BLOCK_NONE;
2026-03-06 22:38:09 +07:00
2026-03-10 20:51:27 +07:00
TFTrendContext g_MiddleTrend;
TFTrendContext g_TriggerTrend;
DailyRiskContext g_DailyRisk;
2026-03-06 22:38:09 +07:00
2026-03-10 20:51:27 +07:00
FVGRecord g_FVGPool[MAX_FVG_POOL];
int g_FVGCount = 0;
int g_NextFVGId = 0;
int g_ActiveFVGIdx = -1;
int g_TradeBarIndex = -1;
2026-03-06 22:38:09 +07:00
2026-03-10 20:51:27 +07:00
OrderPlan g_OrderPlan;
ulong g_PendingTicket = 0;
2026-03-10 23:43:41 +07:00
OrderHistRecord g_OrderHist[MAX_ORDER_HISTORY];
int g_OrderHistCount = 0;
int g_NextOrderHistId = 0;
2026-03-10 20:51:27 +07:00
const string PREFIX_SWING_MIDDLE = "SwingMiddle_";
const string PREFIX_SWING_TRIGGER = "SwingTrigger_";
const string PREFIX_MSS_MARKER = "MSSMarker_";
const string PREFIX_FVG_POOL = "FVGPool_";
const string PREFIX_ORDER_VISUAL = "OrderVisual_";
2026-03-10 23:43:41 +07:00
const string PREFIX_ORDER_HIST = "OrdHist_";
2026-03-10 20:51:27 +07:00
const string PREFIX_DEBUG_PANEL = "DebugPanel_";
2026-03-10 21:17:12 +07:00
const string PREFIX_SESSION = "Session_";
2026-03-10 13:47:42 +07:00
2026-03-10 20:51:27 +07:00
#include "EA_ICT_CL/Contexts.mqh"
#include "EA_ICT_CL/Guards.mqh"
#include "EA_ICT_CL/Signals_BOS_FVG_OB.mqh"
#include "EA_ICT_CL/Trade.mqh"
#include "EA_ICT_CL/StateMachine.mqh"
#include "EA_ICT_CL/Drawing.mqh"
2026-03-06 22:38:09 +07:00
2026-03-10 20:51:27 +07:00
/** Initializes globals, contexts, FVG pool and first draw. */
2026-03-06 22:38:09 +07:00
int OnInit()
{
2026-03-10 22:21:59 +07:00
ZeroMemory(g_MiddleTrend); ZeroMemory(g_TriggerTrend);
2026-03-10 20:51:27 +07:00
ZeroMemory(g_DailyRisk); ZeroMemory(g_OrderPlan);
for (int i = 0; i < MAX_FVG_POOL; i++) ZeroMemory(g_FVGPool[i]);
2026-03-10 23:43:41 +07:00
for (int i = 0; i < MAX_ORDER_HISTORY; i++) ZeroMemory(g_OrderHist[i]);
2026-03-10 20:51:27 +07:00
g_FVGCount = 0; g_NextFVGId = 0;
g_ActiveFVGIdx = -1; g_TradeBarIndex = -1; g_PendingTicket = 0;
2026-03-10 23:43:41 +07:00
g_OrderHistCount = 0; g_NextOrderHistId = 0;
2026-03-10 20:51:27 +07:00
g_State = EA_IDLE; g_BlockReason = BLOCK_NONE;
2026-03-10 23:43:41 +07:00
ObjectsDeleteAll(0, PREFIX_ORDER_VISUAL);
2026-03-06 22:38:09 +07:00
2026-03-10 20:51:27 +07:00
UpdateAllContexts();
2026-03-10 23:43:41 +07:00
UpdateFVGPool();
2026-03-10 20:51:27 +07:00
DrawVisuals();
2026-03-06 22:38:09 +07:00
2026-03-10 22:21:59 +07:00
PrintFormat("✅ ICT EA v4.3 | H1=%s | M5=%s | Pool=%d",
EnumToString(g_MiddleTrend.trend),
2026-03-08 05:18:56 +07:00
EnumToString(g_TriggerTrend.trend), g_FVGCount);
2026-03-10 20:51:27 +07:00
return INIT_SUCCEEDED;
2026-03-06 22:38:09 +07:00
}
2026-03-10 23:43:41 +07:00
/** Each tick: update contexts & FVG pool always; run state machine only when guards pass. */
2026-03-06 22:38:09 +07:00
void OnTick()
{
2026-03-10 20:51:27 +07:00
UpdateAllContexts();
2026-03-10 23:43:41 +07:00
UpdateFVGPool();
2026-03-10 20:51:27 +07:00
if (EvaluateGuards())
RunStateMachine();
2026-03-10 13:47:42 +07:00
else if (g_State != EA_IDLE)
2026-03-10 20:51:27 +07:00
ResetToIdle(EnumToString(g_BlockReason));
if (InpDebugDraw) DrawVisuals();
2026-03-06 22:38:09 +07:00
}
2026-03-10 21:17:12 +07:00
/** Removes swing, session, debug panel objects and redraws chart. */
2026-03-06 22:38:09 +07:00
void OnDeinit(const int reason)
{
2026-03-10 20:51:27 +07:00
ObjectsDeleteAll(0, PREFIX_SWING_MIDDLE);
ObjectsDeleteAll(0, PREFIX_SWING_TRIGGER);
2026-03-10 21:17:12 +07:00
ObjectsDeleteAll(0, PREFIX_SESSION);
2026-03-10 20:51:27 +07:00
ObjectsDeleteAll(0, PREFIX_DEBUG_PANEL);
ChartRedraw(0);
PrintFormat("ICT EA v4.3 deinit | reason=%d | pool=%d", reason, g_FVGCount);
2026-03-10 13:47:42 +07:00
}