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