Fix warningPrinted scope - restructure CheckDailyDrawdown function

This commit is contained in:
2026-03-29 22:27:13 -04:00
parent 04756ef2bd
commit 16b69d251c
2 changed files with 21 additions and 8 deletions

View File

@@ -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;
} }

View File

@@ -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;
} }