no 1 on above is referring to the sum of (B+C+D), so in this case if there's 2 bullish and 1 bearish the equation would be like this (1+1+2). The sum of this equation would be the case no like this,
You must understand how it works first, so I suggest you write a test script
I will try to add some explanation here, but please do the above too
if(A)
{
int sum = int(B + C + D);
switch(sum)
{
case1 :
{
//Bullish// (B + C + D) Only 1 value is true so sum == 1// Execute the code needed for 1 true value// if you need to know which one true you have to use some logic within this code blockbreak;
}
case2 :
{
//Bearish// (B + C + D) Only 2 values are true so sum == 2// Execute the code needed for 2 true values// if you need to know which 2 are true you have to use some logic within this code blockbreak;
}
case3 :
{
//Other// (B + C + D) All values are true so sum == 3// Execute the code needed for 3 true valuesbreak;
}
}
}
I used switch case operator to determine a magic number on different timeframe like this,
int timeframe = Period();
switch(timeframe)
{
case5:
MagicNumber = MagicNumberM5;
break;
case15:
MagicNumber = MagicNumberM15;
break;
case30:
MagicNumber = MagicNumberM30;
break;
case60:
MagicNumber = MagicNumberH1;
break;
case240:
MagicNumber = MagicNumberH4;
break;
default:
Alert("EA is not working in this timeframe");
break;
}
because timeframe returns int with number of 5,15,30,60,240 it so the case number would be those numbers.
Let me tells you what I understand with this problem,
if(A)
{
int sum = int(B + C + D);
switch (sum):
{
//if all bullish then the equation would be (1+1+1) = 3, in this example I should write like this, btw I used int cast not boolean because of thread #3case3:
//if 2 condition bullish and 1 bearish then the equation would be (1+1+2) = 4, in this example I should write like this,case4:
From this 4 rules i need 3 including the entry rules to be true, the conventional way is to make it like this: is there a simpler way to check the condition without many or statement. Here you see sum == 1 so the if statement will always be false
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.
ah I think I got the Idea how to use switch case.
no 1 on above is referring to the sum of (B+C+D), so in this case if there's 2 bullish and 1 bearish the equation would be like this (1+1+2). The sum of this equation would be the case no like this,
is this right?
I think you are getting confused - please read the documentation on switch https://www.mql5.com/en/docs/basis/operators/switch
You must understand how it works first, so I suggest you write a test script
I will try to add some explanation here, but please do the above too
here you see sum == 1 so the if statement will always be false.
Actually, the if statement will always be true. False is zero, and true is non-zero. if(false || 4) equals if(4) equals if(true)
Actually, the if statement will always be true. False is zero, and true is non-zero. if(false || 4) equals if(4) equals if(true)
Ah yes good point - I was thinking of this scenario , which is how I usually explicitly write it:
I should have tested it be be sure.
Nevertheless, it makes me even more enthusiastic about wanting to bracket such statements!
I used switch case operator to determine a magic number on different timeframe like this,
because timeframe returns int with number of 5,15,30,60,240 it so the case number would be those numbers.
Let me tells you what I understand with this problem,
is this wrong?