voitl1979: The code should close all orders but not the last opened. Can anyone help me?
|
|
voitl1979:
The code should close all orders but not the last opened.
void CloseOrders()
{
bool close1=false;
bool delite1=false;
int closez;
RefreshRates();
for(closez=OrdersTotal()-2; closez>=0; closez--)
{
{
bool close1=false;
bool delite1=false;
int closez;
RefreshRates();
for(closez=OrdersTotal()-2; closez>=0; closez--)
{
In addition to whroeder's comments - don't presume that the order with the highest index was the last opened.
You need to check the OrderOpenTime()
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
My code ...
{
bool close1=false;
bool delite1=false;
int closez;
RefreshRates();
for(closez=OrdersTotal()-2; closez>=0; closez--)
{
if(OrderSelect(closez,SELECT_BY_POS,MODE_TRADES))
if(AllSymbols==false && OrderSymbol()!=Symbol())
{
continue;
}
if(OrderType()==OP_BUY)
{
close1=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Violet);
}
if(OrderType()==OP_SELL)
{
close1=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Violet);
}
if(PendingOrders)
{
if(OrderType()==OP_BUYLIMIT)
{
delite1=OrderDelete(OrderTicket());
}
if(OrderType()==OP_SELLLIMIT)
{
delite1=OrderDelete(OrderTicket());
}
if(OrderType()==OP_BUYSTOP)
{
delite1=OrderDelete(OrderTicket());
}
if(OrderType()==OP_SELLSTOP)
{
delite1=OrderDelete(OrderTicket());
}
}
} // for
}