I’m new to MQL4 and need some help to program EA which should:
Open order with S/L and T/P and before or if it hit S/L EA must open new order in opposed direction.
Thanks,
Andrei
int start()
{
if (OrdersTotal() == 0){
OrderSend(Symbol(), OP_BUY,LotsOptimized(),Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Blue);
OrderSend(Symbol(), OP_SELL,LotsOptimized(),Bid, 3, Bid + stop_loss * Point, Ask - take_profit * Point, IDENT, MAGIC, 0, Red);
int i;
for(i=0;i<=OrdersTotal()-1;i++) {
OrderSelect(i, SELECT_BY_POS);
if(OrderTakeProfit()==OP_BUY){
if (OrderStopLoss()-Ask<=0.0005 && OrdersTotal() ==1) {
OrderSend(Symbol(), OP_SELL,LotsOptimized()*2,Bid, 3, Bid + stop_loss * Point, Ask - take_profit * Point, IDENT, MAGIC, 0, Red);
}
if(OrderType()==OP_SELL){
if(OrderStopLoss()-Ask>=0.0005 && OrdersTotal() ==1){
OrderSend(Symbol(), OP_BUY,LotsOptimized()*2,Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Blue);
}
}
i--;
}
}
}
return(0);
}
this "OrderTakeProfit()==OP_BUY" can not work ....
OP_BUY is a constant for the command in OrderSendFunction and is equal to 0.
OrderTakeProfit ist the TakeProfit of the selected order.
i-- ?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I’m new to MQL4 and need some help to program EA which should:
Open order with S/L and T/P and before or if it hit S/L EA must open new order in opposed direction.
Thanks,
Andrei
int start()
{
if (OrdersTotal() == 0){
OrderSend(Symbol(), OP_BUY,LotsOptimized(),Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Blue);
OrderSend(Symbol(), OP_SELL,LotsOptimized(),Bid, 3, Bid + stop_loss * Point, Ask - take_profit * Point, IDENT, MAGIC, 0, Red);
int i;
for(i=0;i<=OrdersTotal()-1;i++) {
OrderSelect(i, SELECT_BY_POS);
if(OrderTakeProfit()==OP_BUY){
if (OrderStopLoss()-Ask<=0.0005 && OrdersTotal() ==1) {
OrderSend(Symbol(), OP_SELL,LotsOptimized()*2,Bid, 3, Bid + stop_loss * Point, Ask - take_profit * Point, IDENT, MAGIC, 0, Red);
}
if(OrderType()==OP_SELL){
if(OrderStopLoss()-Ask>=0.0005 && OrdersTotal() ==1){
OrderSend(Symbol(), OP_BUY,LotsOptimized()*2,Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Blue);
}
}
i--;
}
}
}
return(0);
}