Fix warningPrinted scope - restructure CheckDailyDrawdown function
This commit is contained in:
@@ -631,7 +631,8 @@ bool CheckDailyDrawdown()
|
|||||||
{
|
{
|
||||||
static bool warningPrinted = false;
|
static bool warningPrinted = false;
|
||||||
|
|
||||||
if(InpMaxDailyDrawdown <= 0) return true; // Protection disabled
|
if(InpMaxDailyDrawdown <= 0)
|
||||||
|
return true; // Protection disabled
|
||||||
|
|
||||||
datetime today = TimeCurrent() / 86400 * 86400;
|
datetime today = TimeCurrent() / 86400 * 86400;
|
||||||
if(today != lastEquityReset)
|
if(today != lastEquityReset)
|
||||||
@@ -645,11 +646,13 @@ bool CheckDailyDrawdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);
|
double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);
|
||||||
if(dailyStartEquity <= 0) return true;
|
if(dailyStartEquity <= 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
double drawdownPercent = (dailyStartEquity - currentEquity) / dailyStartEquity * 100;
|
double drawdownPercent = (dailyStartEquity - currentEquity) / dailyStartEquity * 100;
|
||||||
|
bool overLimit = (drawdownPercent >= InpMaxDailyDrawdown);
|
||||||
|
|
||||||
if(drawdownPercent >= InpMaxDailyDrawdown)
|
if(overLimit)
|
||||||
{
|
{
|
||||||
if(!warningPrinted)
|
if(!warningPrinted)
|
||||||
{
|
{
|
||||||
@@ -659,8 +662,11 @@ bool CheckDailyDrawdown()
|
|||||||
}
|
}
|
||||||
return false; // Block new trades
|
return false; // Block new trades
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
warningPrinted = false; // Reset when below limit
|
||||||
|
}
|
||||||
|
|
||||||
warningPrinted = false; // Reset when below limit
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,8 @@ bool CheckDailyDrawdown()
|
|||||||
{
|
{
|
||||||
static bool warningPrinted = false;
|
static bool warningPrinted = false;
|
||||||
|
|
||||||
if(InpMaxDailyDrawdown <= 0) return true; // Protection disabled
|
if(InpMaxDailyDrawdown <= 0)
|
||||||
|
return true; // Protection disabled
|
||||||
|
|
||||||
datetime today = TimeCurrent() / 86400 * 86400;
|
datetime today = TimeCurrent() / 86400 * 86400;
|
||||||
if(today != lastEquityReset)
|
if(today != lastEquityReset)
|
||||||
@@ -142,11 +143,14 @@ bool CheckDailyDrawdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);
|
double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);
|
||||||
if(dailyStartEquity <= 0) return true;
|
if(dailyStartEquity <= 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
double drawdownPercent = (dailyStartEquity - currentEquity) / dailyStartEquity * 100;
|
double drawdownPercent = (dailyStartEquity - currentEquity) / dailyStartEquity * 100;
|
||||||
|
|
||||||
if(drawdownPercent >= InpMaxDailyDrawdown)
|
bool overLimit = (drawdownPercent >= InpMaxDailyDrawdown);
|
||||||
|
|
||||||
|
if(overLimit)
|
||||||
{
|
{
|
||||||
if(!warningPrinted)
|
if(!warningPrinted)
|
||||||
{
|
{
|
||||||
@@ -157,8 +161,11 @@ bool CheckDailyDrawdown()
|
|||||||
}
|
}
|
||||||
return false; // Block new trades
|
return false; // Block new trades
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
warningPrinted = false; // Reset when below limit
|
||||||
|
}
|
||||||
|
|
||||||
warningPrinted = false; // Reset when below limit
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user