How to make a closure order, when the order is positive? I tried to do as in the example below, but sometimes occurs in close negative?
Answer I look!
for(int a=0;a<OrdersTotal();a++)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==false) break;
//---- check order type
if(OrderType()==OP_BUY)
{
if (OrderClosePrice() > (OrderOpenPrice()+OrderSwap()+OrderCommission()))
OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
}
if(OrderType()==OP_SELL)
{
if (OrderClosePrice() < (OrderOpenPrice()+OrderSwap()+OrderCommission()))
OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
}
}
1. Your loop counter should be decrementing (not incrementing as it is now). See -> https://www.mql5.com/en/forum/119840
2. You are trying to add OrderOpenPrice() which returns a price value, to OrderSwap() and OrderCommission() which return money value (trying to add 2 values with different 'units'), that won't work.
There is an accumulation of open orders, it might change something in the analysis.
The link you showed only closes the order, does not mean it closes positive, I want to close always positive, the way I closed positive start after error occurs and closes some negative orders.
I did not say it closes positive. Your loop counter is incrementing, that won't work properly with closing orders, regardless of if they close positive or not.
Thanks,
I made these changes and this perfect
for(int a=OrdersTotal() - 1; a >= 0; a--)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==false) break;
//---- check order type
RefreshRates ();
if(OrderType()==OP_BUY)
{
if (Bid > OrderOpenPrice())
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Blue);
}
if(OrderType()==OP_SELL)
{
if (Ask < OrderOpenPrice()) //+OrderSwap()+OrderCommission()))
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red);
}
}
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to make a closure order, when the order is positive? I tried to do as in the example below, but sometimes occurs in close negative?
Answer I look!
for(int a=0;a<OrdersTotal();a++)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==false) break;
//---- check order type
if(OrderType()==OP_BUY)
{
if (OrderClosePrice() > (OrderOpenPrice()+OrderSwap()+OrderCommission()))
OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
}
if(OrderType()==OP_SELL)
{
if (OrderClosePrice() < (OrderOpenPrice()+OrderSwap()+OrderCommission()))
OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
}
}