Download MetaTrader 5
To add comments, please log in or register
All activity at MQL5.community is clearly visible. Have a look at the Wall!
brettosm8
241
brettosm8 2015.12.07 08:02 

Hi there,

I manually opened a BUY order and ran the below code:

void OnStart()
  {
//---
   for(int i=OrdersTotal();i>0; i--)
     {
      Print("OrdersTotal: ",OrdersTotal());
      
      if(OrderSelect(i,SELECT_BY_POS)==false) Print("Unable to close order. Error: ",GetLastError());
      
      Print("Ticket: ",OrderTicket());
      Print("Lots ",OrderLots());

      if(OrderType()==0)//BUY
        {
         if(OrderClose(OrderTicket(),OrderLots(),Bid,4,Red)==false) Print("Unable to close order. Error: ",GetLastError());
        }
      else if(OrderType()==1)//SELL
        {
         if(OrderClose(OrderTicket(),OrderLots(),Ask,4,Red)==false) Print("Unable to close order. Error: ",GetLastError());
        }
     }
  }

 It generated the below output:

 

 The trade tab shows an active order of 0.01 lots:

 

 What changes do I need to make to be able to delete active orders please?

Kind regards. 

Keith Watford
Moderator
7887
Keith Watford 2015.12.07 08:29  
for(int i=OrdersTotal();i>0; i--)

Change to

for(int i=OrdersTotal()-1;i>=0; i--)

 .

ThreadHandle
105
ThreadHandle 2015.12.07 11:04  
for(int i = 0; i < OrdersTotal(); i++)

i should be 0 and count upto OrdersTotal()

Just so you know, your OrderSelect(i, SELECT_BY_POS) starts from 0, if you have 1 order, selecting order 1 wont exist because its indexed from 0 like most arrays.

Keith Watford
Moderator
7887
Keith Watford 2015.12.07 11:17  

Keelan:

for(int i = 0; i < OrdersTotal(); i++)

 i should be 0 and count upto OrdersTotal()


 Absolutely not!!

 When closing orders ALWAYS count down. 

whroeder1
13596
whroeder1 2015.12.07 13:18  
In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
brettosm8
241
brettosm8 2015.12.09 06:05  

Thanks. 

ThreadHandle
105
ThreadHandle 2015.12.09 18:47  
Why? i iterate through my Orders in ascending order and nothings broke yet, dont have to use FIFO or LIFO? or is it an mql thing? 
Keith Watford
Moderator
7887
Keith Watford 2015.12.09 20:56  
Keelan:
Why? i iterate through my Orders in ascending order and nothings broke yet, dont have to use FIFO or LIFO? or is it an mql thing? 
WHRoeder posted a link that will tell you why
Mahmoud Farajpour
203
Mahmoud Farajpour 2015.12.14 10:40  
Hi im new..

there is a function to selecting a symbol :

SymbolSelect();

i dont know how to use it in order to select for example EURUSD symbol, can you please write exactly the code which select the symbol EURUSD ?

thanks
Keith Watford
Moderator
7887
Keith Watford 2015.12.14 10:50  
mahmood0:
Hi im new..

there is a function to selecting a symbol :

SymbolSelect();

idont know how to use it in order to select for example EURUSD symbol,can you please write exactly the code which select the symbol EURUSD ?

thanks

I am wasting a lot of time deleting your replicated posts.

Don't double post

You are banned for 1 month and lucky that it is not permanent!

/
To add comments, please log in or register