See what happens when you remove the "Print("IO1 true");" line
You need to link if statements or have a loop following a non bracketed if , you get one "next line" of code to link what goes in the if block .
So in the example above as is the 1st Print is taking up that line and then what follows belongs to the function scope not the if(IO1)
Similarly , if you remove the 1st print then the if(!IO2) belongs to the if(IO1) but the if(!IO2&&!IO1) belongs to the function scope, unless it was an else if (linking to the previous which was part of the if(IO1) block.
See what happens when you remove the "Print("IO1 true");" line
You need to link if statements or have a loop following a non bracketed if , you get one "next line" of code to link what goes in the if block .
So in the example above as is the 1st Print is taking up that line and then what follows belongs to the function scope not the if(IO1)
Similarly , if you remove the 1st print then the if(!IO2) belongs to the if(IO1) but the if(!IO2&&!IO1) belongs to the function scope, unless it was an else if (linking to the previous which was part of the if(IO1) block.
Yes you are right … if you remove that line, then second if will be executed only if first if is true … good to know … normally I use brackets as is styling better, but good to know. Thanks
USE_INDICATOR-X_FOR_ENTRY = false;
if(USE_INDICATOR-X_FOR_ENTRY) //if a specific indicator "the flag USE_INDICATOR-X_FOR_ENTRY" is used to confirm entry in position
Do not post code that will not even compile. "A - B = false;" is nonsense.
I recommend using braces - especially with multiple-lined ifs’. I think here the “else” part is not properly read.
For example, here –this second else is connected to “signal type” condition or “indicator X for entry” condition? Add proper braces and it should work then.
if(gobuy == 1) //if a Buy signal was found
{
openPrice = Open[0];
indicatorX_down = iCustom(_Symbol,PERIOD_CURRENT,"indicator-x",2,0);
Print("open price: ", openPrice, " - Indicator-X down: ", indicatorX_down);
if(SIGNAL_TYPE == 0 || SIGNAL_TYPE == 2){ //means BUY signals are allowed by the variable SIGNAL_TYPEif(USE_INDICATOR-X_FOR_ENTRY) { //if a specific indicator "the flag USE_INDICATOR-X_FOR_ENTRY" is used to confirm entry in positionif(openPrice < indicatorX_down)
{
datetime time = iTime(NULL,0,1);
Print("Indicator-X Buy Entry condition met");
if(PushAlert)SendNotification(Symbol()+" BUY @ Hour "+string(Hour())+" Minute "+string(Minute()));
if(EmailOn)SendMail("PC BUY SIGNAL - "+ChartSymbol(0)+" "+string(_Period),string(time)+" - Buy - "+ChartSymbol(0)+"\r\n");
orderCount +=1;
inBuy=true;
Print("In buy: ", IntegerToString(inBuy));
}
else{
Print("Indicator-X Buy Entry condition not met");
}
}
else
{
Print("Indicator-x condition not used"); //////THIS PART OF CODE IS NOT EXECUTED ALTHOUGH FLAG USE_INDICATOR-X_FOR ENTRY IS FALSE///////datetime time = iTime(NULL,0,1);
if(PushAlert)SendNotification(Symbol()+" BUY @ Hour "+string(Hour())+" Minute "+string(Minute()));
if(EmailOn)SendMail("PC BUY SIGNAL - "+ChartSymbol(0)+" "+string(_Period),string(time)+" - Buy - "+ChartSymbol(0)+"\r\n");
orderCount +=1;
inBuy=true;
Print("In buy: ", IntegerToString(inBuy));
}
}
}
Daniel Cioca #: Yes you are right … if you remove that line, then second if will be executed only if first if is true … good to know … normally I use brackets as is styling better, but good to know. Thanks
I recommend using braces - especially with multiple-lined ifs’. I think here the “else” part is not properly read.
For example, here –this second else is connected to “signal type” condition or “indicator X for entry” condition? Add proper braces and it should work then.
See what happens when you remove the "Print("IO1 true");" line
You need to link if statements or have a loop following a non bracketed if , you get one "next line" of code to link what goes in the if block .
So in the example above as is the 1st Print is taking up that line and then what follows belongs to the function scope not the if(IO1)
Similarly , if you remove the 1st print then the if(!IO2) belongs to the if(IO1) but the if(!IO2&&!IO1) belongs to the function scope, unless it was an else if (linking to the previous which was part of the if(IO1) block.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
another test if it helps :
See what happens when you remove the "Print("IO1 true");" line
You need to link if statements or have a loop following a non bracketed if , you get one "next line" of code to link what goes in the if block .
So in the example above as is the 1st Print is taking up that line and then what follows belongs to the function scope not the if(IO1)
Similarly , if you remove the 1st print then the if(!IO2) belongs to the if(IO1) but the if(!IO2&&!IO1) belongs to the function scope, unless it was an else if (linking to the previous which was part of the if(IO1) block.
another test if it helps :
See what happens when you remove the "Print("IO1 true");" line
You need to link if statements or have a loop following a non bracketed if , you get one "next line" of code to link what goes in the if block .
So in the example above as is the 1st Print is taking up that line and then what follows belongs to the function scope not the if(IO1)
Similarly , if you remove the 1st print then the if(!IO2) belongs to the if(IO1) but the if(!IO2&&!IO1) belongs to the function scope, unless it was an else if (linking to the previous which was part of the if(IO1) block.
Do not post code that will not even compile. "A - B = false;" is nonsense.
Hi
I recommend using braces - especially with multiple-lined ifs’. I think here the “else” part is not properly read.
For example, here –this second else is connected to “signal type” condition or “indicator X for entry” condition? Add proper braces and it should work then.
Yes you are right … if you remove that line, then second if will be executed only if first if is true … good to know … normally I use brackets as is styling better, but good to know. Thanks
Thanks Fernando, this is actually what i was doing but it was not working....i will check yours and see if all will be good.
Hi
I recommend using braces - especially with multiple-lined ifs’. I think here the “else” part is not properly read.
For example, here –this second else is connected to “signal type” condition or “indicator X for entry” condition? Add proper braces and it should work then.
another test if it helps :
See what happens when you remove the "Print("IO1 true");" line
You need to link if statements or have a loop following a non bracketed if , you get one "next line" of code to link what goes in the if block .
So in the example above as is the 1st Print is taking up that line and then what follows belongs to the function scope not the if(IO1)
Similarly , if you remove the 1st print then the if(!IO2) belongs to the if(IO1) but the if(!IO2&&!IO1) belongs to the function scope, unless it was an else if (linking to the previous which was part of the if(IO1) block.