# Execute function if variable x is more than variable y

28

Using MQL4, how can I execute a BUY order (seen below) if one variable x has a value of 1 and another variable y has a value of 3? I need it to work like this:

Variable x = 1

Variable y = 3

So if x is MORE THAN y, execute this script:

```extern int TakeProfit = 10;
extern int StopLoss = 10;

void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;

TakeProfitLevel = Bid + TakeProfit*Point;
StopLossLevel = Bid - StopLoss*Point;

```

}

And if x is LESS THAN y, execute this SELL script:

```extern int TakeProfit = 10;
extern int StopLoss = 10;

void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;

TakeProfitLevel = Bid + TakeProfit*Point;
StopLossLevel = Bid - StopLoss*Point;

```

}

I'm struggling to find the MQL4 code which establishes variables which can then be compared against each other e.g. x > y and vice versa, so any help would be greatly appreciated.
Moderator
10372

```if(x>y)
{
}
else
if(x<y)
{
//Execute Sell order
}```

.

Moderator
10372

pluck6:

but how do I establish the variables? Would it be something like this:

var x = 1;

var y = 3;

That wouldn't make sense. There would have to be some conditions that would assign a value to the variables.

Finally, should I wrap this whole code within void OnStart() {} ?

Either that or in a function.
2201

pluck6: I'm struggling to find the MQL4 code which establishes variables which can then be compared against each other e.g. x > y and vice versa, so any help would be greatly appreciated.
• Before programing in MQL4, I suggest you first familiarise yourself with code in general such as in a language called "C".
• After that, read through the "MQL4 Book/Tutorial" section on this site, which will introduce you to all the basic things you first need to learn, such as how to declare variables, etc.
• When in doubt, and before posting here, always consult the Documentation, whether that be the Online Version on via the Help (F1) in the Editor/Compiler.
15331

learn to code it, or pay someone. We're not going to code it FOR you.