I need help to correct this code, it is keep alerting continuously when margin < 200 , but I want only once.!!!
use the source </> button to enter code
void marginlevelwarning() { static bool StopAlert = false; double freemargin = MathRound(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL)); if(freemargin >= 200) StopAlert = false; else if(StopAlert == false) { Alert("Margin Level Low : ", freemargin," %."); StopAlert = true; // stop further alerts until >= 200 and drops below 200 } }
I need help to correct this code, it is keep alerting continuously when margin < 200 , but I want only once.!!!
void marginlevelwarning() { double freemargin = MathRound(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL)); if (freemargin < 200) { Alert("Margin Level Low : ", freemargin," %."); } }
Declare a global boolean variable or a static boolean variable called maybe "isAlertTriggered" and set it to false and add it to "if( !isAlertTriggered && freemargin < 0)" condition. Add a line of code after the condition to assign the value true to this boolean variable. This way you won't get another new alert again even if the freemargin condition is still true.
You are looking at a signal. Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 (2017)
Thanks for help. I got it.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need help to correct this code, it is keep alerting continuously when margin < 200 , but I want only once.!!!
void marginlevelwarning()
{
double freemargin = MathRound(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL));
if (freemargin < 200)
{
Alert("Margin Level Low : ", freemargin," %.");
}
}