Liquidity_Predator/Strategy/M_CheckLiquCrossed.mqh

84 lines
No EOL
3.6 KiB
MQL5

bool M_CheckLiquCrossed()
{
// Check if sellside liquidity got activated (crossed)
for(int i = 0; i <= ArraySize(stGVL.SellLiquidity) - 1; i++)
{
if(stGVL.Candle[1].high > stGVL.SellLiquidity[i]) // check the last closed candle and not the current one to increase performance
{
if(stGVL.nStateMachine == SM_IN_TRADE) // In trade, do nothing
{
M_LogInfo("Sellside liquidity activated and deleted because in trade" + DoubleToString(stGVL.SellLiquidity[i]));
}
else
{
stGVL.CurrentLiquidity = stGVL.SellLiquidity[i];
stGVL.dtCurrentLiquidity_Time = stGVL.Candle[1].time; // save time of Liquidity activation
stGVL.eCurrentDirection = DIR_SHORT;
stGVL.Line_ActLiqu_Number = stGVL.Line_ActLiqu_Number + 1;
M_SetLine(stGVL.Line_ActLiqu, stGVL.Line_ActLiqu_Number, stGVL.CurrentLiquidity, clrOrange);
if(stGVL.Candle[1].high - stGVL.CurrentLiquidity > stGVL.fMaxDiffTakeOut_Price && stGVL.fMaxDiffTakeOut_Price!=0)
{
M_LogWarning("Sell-Liquidity got taken out " + DoubleToString(stGVL.Candle[1].high - stGVL.CurrentLiquidity));
stGVL.CurrentLiquidity = 0;
stGVL.nStateMachine = SM_RESET;
}
else if(!M_PatternBeforeLiquOK())
{
stGVL.CurrentLiquidity = 0;
stGVL.nStateMachine = SM_RESET;
}
else
{
string Message = "Sellside liquidity activated at " + DoubleToString(stGVL.CurrentLiquidity);
M_LogInfo(Message);
stGVL.nStateMachine = SM_LIQUIDITY_ACTIVATED;
}
}
stGVL.SellLiquidity[i] = 100000000000; // Reset value to 100_000_000_000 so it can never get activated
}
}
// Check if buyside liquidity got activated (crossed)
for(int i = 0; i <= ArraySize(stGVL.SellLiquidity) - 1; i++)
{
if(stGVL.Candle[1].low < stGVL.BuyLiquidity[i]) // check the last closed candle and not the current one to increase performance
{
if(stGVL.nStateMachine == SM_IN_TRADE) // In trade, do nothing
{
M_LogInfo("Sellside liquidity activated and deleted because in trade" + DoubleToString(stGVL.BuyLiquidity[i]));
}
else
{
stGVL.CurrentLiquidity = stGVL.BuyLiquidity[i];
stGVL.dtCurrentLiquidity_Time = stGVL.Candle[1].time; // save time of Liquidity activation
stGVL.eCurrentDirection = DIR_LONG;
stGVL.Line_ActLiqu_Number = stGVL.Line_ActLiqu_Number + 1;
M_SetLine(stGVL.Line_ActLiqu, stGVL.Line_ActLiqu_Number, stGVL.CurrentLiquidity, clrOrange);
if(stGVL.CurrentLiquidity - stGVL.Candle[1].low > stGVL.fMaxDiffTakeOut_Price && stGVL.fMaxDiffTakeOut_Price!=0)
{
M_LogWarning("Buy-Liquidity got taken out " + DoubleToString(stGVL.CurrentLiquidity - stGVL.Candle[1].low));
stGVL.CurrentLiquidity = 0;
stGVL.nStateMachine = SM_RESET;
}
else if(!M_PatternBeforeLiquOK())
{
stGVL.CurrentLiquidity = 0;
stGVL.nStateMachine = SM_RESET;
}
else
{
string Message = "Buyside liquidity activated at " + DoubleToString(stGVL.CurrentLiquidity);
M_LogInfo(Message);
stGVL.nStateMachine = SM_LIQUIDITY_ACTIVATED;
}
}
stGVL.BuyLiquidity[i] = 0; // Reset value to 0 so it can never get activated
}
}
return true;
}