Execute function if variable x is more than variable y

 

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;

   Alert("TakeProfitLevel = ", TakeProfitLevel);
   Alert("StopLossLevel = ", StopLossLevel);

   OrderSend("USDCAD", OP_BUY, 1.0, Ask, 10, StopLossLevel, TakeProfitLevel, "first order");
 

 }

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;

Alert("TakeProfitLevel = ", TakeProfitLevel);
Alert("StopLossLevel = ", StopLossLevel);

OrderSend("USDCAD", OP_SELL, 1.0, Ask, 10, StopLossLevel, TakeProfitLevel, "first order");
 

}

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. 
 
if(x>y)
   {
    //Execute Buy order
   }
else 
if(x<y)
   {
    //Execute Sell order
   }

.

 
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.
 
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.
 
learn to code it, or pay someone. We're not going to code it FOR you.
We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
Reason: