Hello,
I am making a code,
If Buy Order reach above 30 Point from Entry price, close Sell Order
If Sell Order reach below 30 Point from Entry Price, Close Buy Order.
Problem :
Both condition some how getting true and it closing both Buy and Sell order at same time
I am making a code,
If Buy Order reach above 30 Point from Entry price, close Sell Order
If Sell Order reach below 30 Point from Entry Price, Close Buy Order.
MQL4:
int gRangeClosing_Automatic = 30; if((LastOrderPrice(OP_SELL, gSellMagic) - Ask) / Point > gRangeClosing_Automatic) { CloseOpenAndPendingTrades(gBuyMagic); Print("Range Closing => Buy Order Closed"); } if((Bid - LastOrderPrice(OP_BUY, gBuyMagic)) / Point > gRangeClosing_Automatic) { CloseOpenAndPendingTrades(gSellMagic); Print("Range Closing => Sell Order Closed"); } double LastOrderPrice(int LastOrderPrice_OrderType, int LastOrderPrice_magic) { double LastOrderPrice_Price = 0; // Initialize to some default value for(int pos_12 = 0; pos_12 < OrdersTotal(); pos_12++) { OrderSelect(pos_12, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol() != Symbol() || OrderMagicNumber() != LastOrderPrice_magic) continue; if(OrderType() == LastOrderPrice_OrderType) LastOrderPrice_Price = OrderOpenPrice(); } return LastOrderPrice_Price; }
Problem :
Both condition some how getting true and it closing both Buy and Sell order at same time