Liquidity_Predator/Strategy/M_SM_S1_WAIT_FVG_CREATED.mqh

77 lines
4.1 KiB
MQL5
Raw Permalink Normal View History

2026-04-30 15:51:09 +02:00
void M_SM_S1_WAIT_FVG_CREATED()
{
// Direction Buy
2026-05-03 19:29:52 +02:00
if(stGVL.Candle[2].close > stGVL.CurrentLiquidity + stGVL.nS1MaxDiffFVGLiquCross_Price && stGVL.nS1MaxDiffFVGLiquCross_Price != 0 && stGVL.eCurrentDirection == DIR_LONG)
2026-04-30 15:51:09 +02:00
{
M_LogInfo("Strat1, Abort because price is too far away from liquidity");
stGVL.nStateMachine = SM_RESET;
}
if(stGVL.CurrentLiquidity - stGVL.Candle[0].low > stGVL.nS1MaxDiffTakeout_Price && stGVL.nS1MaxDiffTakeout_Price != 0 && stGVL.eCurrentDirection == DIR_LONG)
2026-04-30 16:53:46 +02:00
{
M_LogInfo("Strat1, Buy-Liquidity got taken out " + DoubleToString(stGVL.CurrentLiquidity - stGVL.Candle[0].low));
stGVL.nStateMachine = SM_RESET;
}
2026-04-30 15:51:09 +02:00
if(stGVL.Candle[2].open < stGVL.Candle[2].close && stGVL.eCurrentDirection == DIR_LONG) // middle candle is bullish
{
// Gap between Candle i and i+2 existing and is big enough
2026-05-22 12:44:33 +02:00
bool Condition1 = stGVL.Candle[3].high + stGVL.fMinSizeFVG_Price < stGVL.Candle[1].low;
2026-04-30 15:51:09 +02:00
// Gap between Candle i and i+2 is not too big
bool Condition2 = stGVL.Candle[1].low - stGVL.Candle[3].high < stGVL.fMaxSizeFVG_Price || stGVL.fMaxSizeFVG_Price == 0;
// FVG is above current liquidity
bool Condition3 = stGVL.Candle[3].high > stGVL.CurrentLiquidity;
if(Condition1 && Condition2 && Condition3)
{ // fair value gap
stGVL.LastFVGTop = stGVL.Candle[1].low;
stGVL.LastFVGBottom = stGVL.Candle[3].high;
stGVL.LastFVGIndex = 2;
datetime barTime = iTime(_Symbol, PERIOD_CURRENT, 0);
stGVL.Rect_ActFVG_Number = stGVL.Rect_ActFVG_Number + 1;
M_CreateBox(stGVL.Rect_FVG, stGVL.Rect_ActFVG_Number, barTime - 60 * stGVL.LastFVGIndex, barTime, stGVL.LastFVGTop, stGVL.LastFVGBottom, clrYellow);
string Message = "Strat1, FVG for buy found, TOP=" + DoubleToString(stGVL.LastFVGTop) + " BOTTOM=" + DoubleToString(stGVL.LastFVGBottom) + " Index=" + IntegerToString(stGVL.LastFVGIndex);
M_LogInfo(Message);
stGVL.nStateMachine = SM_S1_WAIT_FVG_INVERTED;
}
}
// Direction Sell
2026-05-03 19:29:52 +02:00
else if(stGVL.Candle[2].close < stGVL.CurrentLiquidity - stGVL.nS1MaxDiffFVGLiquCross_Price && stGVL.nS1MaxDiffFVGLiquCross_Price != 0 && stGVL.eCurrentDirection == DIR_SHORT)
2026-04-30 15:51:09 +02:00
{
M_LogInfo("Strat1, Abort because price is too far away from liquidity");
stGVL.nStateMachine = SM_RESET;
}
else if(stGVL.Candle[0].high - stGVL.CurrentLiquidity > stGVL.nS1MaxDiffTakeout_Price && stGVL.nS1MaxDiffTakeout_Price != 0 && stGVL.eCurrentDirection == DIR_SHORT)
2026-04-30 16:53:46 +02:00
{
M_LogInfo("Strat1, Sell-Liquidity got taken out " + DoubleToString(stGVL.Candle[0].high - stGVL.CurrentLiquidity));
stGVL.nStateMachine = SM_RESET;
}
2026-04-30 15:51:09 +02:00
else if(stGVL.Candle[2].open > stGVL.Candle[2].close && stGVL.eCurrentDirection == DIR_SHORT) // middle candle is bearish
{
// Gap between Candle i and i+2 existing and is big enough
2026-05-22 12:44:33 +02:00
bool Condition1 = stGVL.Candle[1].high + stGVL.fMinSizeFVG_Price < stGVL.Candle[3].low;
2026-04-30 15:51:09 +02:00
// Gap between Candle i and i+2 is not too big
bool Condition2 = stGVL.Candle[3].low - stGVL.Candle[1].high < stGVL.fMaxSizeFVG_Price || stGVL.fMaxSizeFVG_Price == 0;
// FVG is above current liquidity
bool Condition3 = stGVL.Candle[3].low < stGVL.CurrentLiquidity;
if(Condition1 && Condition2 && Condition3)
{ // fair value gap
stGVL.LastFVGTop = stGVL.Candle[3].low;
stGVL.LastFVGBottom = stGVL.Candle[1].high;
stGVL.LastFVGIndex = 2;
datetime barTime = iTime(_Symbol, PERIOD_CURRENT, 0);
stGVL.Rect_ActFVG_Number = stGVL.Rect_ActFVG_Number + 1;
M_CreateBox(stGVL.Rect_FVG, stGVL.Rect_ActFVG_Number, barTime - 60 * stGVL.LastFVGIndex, barTime, stGVL.LastFVGTop, stGVL.LastFVGBottom, clrYellow);
string Message = "Strat1, FVG for sell found, TOP=" + DoubleToString(stGVL.LastFVGTop) + " BOTTOM=" + DoubleToString(stGVL.LastFVGBottom) + " Index=" + IntegerToString(stGVL.LastFVGIndex);
M_LogInfo(Message);
stGVL.nStateMachine = SM_S1_WAIT_FVG_INVERTED;
}
}
}