# IF Then code for MT4

911

I need some help. I want to setup a If then type of situation.

I'm trying to setup a situation where I get a signal from a indicator to buy or sell then I want another set of conditions met before a trade is open regardless of how many candles it takes to happen. I know how to write a if situation but not a if then, if that's possible. Any help would be appreciated or if you can direct me to a link where I can read up in this.

Thanks

Moderator
13927

Use a global/static boolean flag.

When the conditions are met, set the bool to true.

Check for the 2nd set of conditions only when that bool is true.

Remember to re-set the bool to false when you want to start over.

1123

cpickens:

I need some help. I want to setup a If then type of situation.

I'm trying to setup a situation where I get a signal from a indicator to buy or sell then I want another set of conditions met before a trade is open regardless of how many candles it takes to happen. I know how to write a if situation but not a if then, if that's possible. Any help would be appreciated or if you can direct me to a link where I can read up in this.

Thanks

Too theoretical question... maybe a pseudo-code or more explanation about your exactly doubt?  Is your problem about raw code itself or conceptual separation of "objects of decision" / event-driven decisions?
4334

cpickens: I need some help. I want to setup a If then type of situation. I'm trying to setup a situation where I get a signal from a indicator to buy or sell then I want another set of conditions met before a trade is open regardless of how many candles it takes to happen. I know how to write a if situation but not a if then, if that's possible. Any help would be appreciated or if you can direct me to a link where I can read up in this.
```//--- The else part refers to the second if operator:
if(x>1)
if(y==2) z=5;
else     z=6;
//--- The else part refers to the first if operator:
if(x>l)
{
if(y==2) z=5;
}
else        z=6;
//--- Nested operators
if(x=='a')
{
y=1;
}
else if(x=='b')
{
y=2;
z=3;
}
else if(x=='c')
{
y=4;
}
else Print("ERROR");```

Documentation on MQL5: Language Basics / Operators / Conditional Operator if-else
• www.mql5.com
If the expression is true, operator1 is executed and control is given to the operator that follows operator2 (operator2 is not executed). If the expression is false, operator2 is executed.