2026-03-11 16:06:24 +07:00
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
//| Config.mqh – Step 0: Inputs, Enums, Constants |
|
|
|
|
|
|
//| Cho phép cấu hình symbol, timeframe, EMA, FVG, drawing |
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
#ifndef __SIMPLE_FVG_CONFIG_MQH__
|
|
|
|
|
|
#define __SIMPLE_FVG_CONFIG_MQH__
|
|
|
|
|
|
|
|
|
|
|
|
//--- Step 0: Asset & Timeframe ---
|
2026-03-11 18:13:27 +07:00
|
|
|
|
input string InpSymbol = "";
|
|
|
|
|
|
input ENUM_TIMEFRAMES InpTimeframe = PERIOD_H1;
|
2026-03-11 16:06:24 +07:00
|
|
|
|
|
|
|
|
|
|
//--- Step 1: Trend (EMA) ---
|
2026-03-11 18:13:27 +07:00
|
|
|
|
input int InpEMAFastPeriod = 34;
|
|
|
|
|
|
input int InpEMASlowPeriod = 89;
|
2026-03-11 16:06:24 +07:00
|
|
|
|
|
|
|
|
|
|
//--- Step 2: FVG Detection ---
|
2026-05-09 23:16:50 +07:00
|
|
|
|
input int InpFVGLookbackBars = 120;
|
|
|
|
|
|
input int InpFVGMaxAgeBars = 36;
|
|
|
|
|
|
input double InpFVGMinBodyPct = 55.0;
|
|
|
|
|
|
input double InpFVGMinSizePoints = 120;
|
|
|
|
|
|
input double InpFVGTouchedPercent = 35.0;
|
|
|
|
|
|
input double InpFVGMinGapVsImpulsePct = 35.0;
|
2026-03-11 19:08:21 +07:00
|
|
|
|
input double InpFVGMaxOuterBarRatio = 2.0;
|
2026-03-11 18:13:27 +07:00
|
|
|
|
|
|
|
|
|
|
//--- Step 3: Trading ---
|
|
|
|
|
|
input bool InpTradeEnabled = true;
|
2026-05-09 23:16:50 +07:00
|
|
|
|
input double InpRiskPercentPerR = 1;
|
2026-03-11 23:57:35 +07:00
|
|
|
|
input double InpRRRatio = 2.2;
|
2026-05-09 23:16:50 +07:00
|
|
|
|
input int InpMaxLimitOrders = 1;
|
|
|
|
|
|
input int InpLimitMaxAgeBars = 12;
|
2026-03-11 18:13:27 +07:00
|
|
|
|
input long InpEAMagic = 123456;
|
2026-05-09 23:16:50 +07:00
|
|
|
|
input int InpMaxSpreadPoints = 350; // XAUUSD-friendly default
|
|
|
|
|
|
input bool InpUseSessionFilter = true;
|
|
|
|
|
|
input int InpSessionStartHour = 7; // server time hour [0..23]
|
|
|
|
|
|
input int InpSessionEndHour = 23; // server time hour [0..23], supports overnight window
|
|
|
|
|
|
input bool InpUseATRFilter = true;
|
|
|
|
|
|
input int InpATRPeriod = 14;
|
|
|
|
|
|
input double InpMinATRPoints = 1200; // skip low-volatility regime
|
|
|
|
|
|
input double InpMaxATRPoints = 7000; // skip extreme-volatility regime
|
|
|
|
|
|
input double InpLowTFEntryRangeBufferPoints = 60; // HTF-LTF mapping tolerance
|
2026-03-11 16:06:24 +07:00
|
|
|
|
|
|
|
|
|
|
//--- Step 4: Drawing ---
|
2026-03-11 18:13:27 +07:00
|
|
|
|
input color InpColorBullFVG = C'30,80,140';
|
|
|
|
|
|
input color InpColorBearFVG = C'140,30,20';
|
|
|
|
|
|
input color InpColorMitigatedFVG = C'60,60,60';
|
|
|
|
|
|
input color InpColorEMAFast = clrDodgerBlue;
|
|
|
|
|
|
input color InpColorEMASlow = clrOrangeRed;
|
|
|
|
|
|
input bool InpShowPanel = true;
|
|
|
|
|
|
input bool InpShowFVGLabels = true;
|
2026-03-11 16:06:24 +07:00
|
|
|
|
|
|
|
|
|
|
//--- Debug ---
|
2026-03-11 18:13:27 +07:00
|
|
|
|
input bool InpDebugLog = true;
|
2026-03-11 16:06:24 +07:00
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
//| Enums |
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
enum ENUM_TREND_DIRECTION
|
|
|
|
|
|
{
|
|
|
|
|
|
TREND_BULLISH = 1,
|
|
|
|
|
|
TREND_BEARISH = -1,
|
|
|
|
|
|
TREND_NEUTRAL = 0
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum ENUM_FVG_TYPE
|
|
|
|
|
|
{
|
|
|
|
|
|
FVG_BULLISH = 1,
|
|
|
|
|
|
FVG_BEARISH = -1
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-11 18:13:27 +07:00
|
|
|
|
enum ENUM_FVG_STATUS
|
|
|
|
|
|
{
|
|
|
|
|
|
ACTIVE = 0, // Giá chưa quay lại test
|
|
|
|
|
|
TOUCHED = 1, // Giá đã retest >= threshold %
|
|
|
|
|
|
MITIGATED = 2, // Giá đâm xuyên qua vùng
|
|
|
|
|
|
EXPIRED = 3 // Hết hạn, không còn vẽ/đếm
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-11 16:06:24 +07:00
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
//| Constants |
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
const string EA_PREFIX = "SFVG_";
|
|
|
|
|
|
const int MAX_FVG_SLOTS = 50;
|
|
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
//| Resolved symbol (cached) |
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
string g_ResolvedSymbol = "";
|
|
|
|
|
|
|
|
|
|
|
|
string GetTradeSymbol()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(g_ResolvedSymbol != "")
|
|
|
|
|
|
return g_ResolvedSymbol;
|
|
|
|
|
|
|
|
|
|
|
|
g_ResolvedSymbol = (InpSymbol == "" || InpSymbol == "current")
|
|
|
|
|
|
? _Symbol
|
|
|
|
|
|
: InpSymbol;
|
|
|
|
|
|
return g_ResolvedSymbol;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
//| New-bar detector |
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
datetime g_PreviousBarTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
bool IsNewBar()
|
|
|
|
|
|
{
|
|
|
|
|
|
datetime currentBarTime = iTime(GetTradeSymbol(), InpTimeframe, 0);
|
|
|
|
|
|
if(currentBarTime == g_PreviousBarTime)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
g_PreviousBarTime = currentBarTime;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 21:22:25 +07:00
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
//| Low TF dùng để xác nhận khi giá chạm FVG: H1->M5, H4->M15, M15->M2 |
|
|
|
|
|
|
//| Trả về low TF hoặc chính highTF nếu không có mapping (không dùng confirm) |
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
ENUM_TIMEFRAMES GetConfirmationTimeframe(ENUM_TIMEFRAMES highTF)
|
|
|
|
|
|
{
|
2026-03-11 23:57:35 +07:00
|
|
|
|
switch(highTF)
|
|
|
|
|
|
{
|
|
|
|
|
|
case PERIOD_M15: return PERIOD_M1;
|
|
|
|
|
|
case PERIOD_H1: return PERIOD_M5;
|
|
|
|
|
|
case PERIOD_H4: return PERIOD_M15;
|
|
|
|
|
|
case PERIOD_D1: return PERIOD_H1;
|
|
|
|
|
|
default: return highTF;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 21:22:25 +07:00
|
|
|
|
return highTF;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 16:06:24 +07:00
|
|
|
|
#endif
|