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.