[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 412

 

Colleagues, could you please answer the following question?
I open 4 buy orders by hand, I run an EA that deletes the set orders at Bid price, slippage is 100 pips, deletion in a loop, thread occupancy check and quote update are present. Why aren't all orders deleted in the loop? The log shows that the deletion takes a few initializations of the start() function

int start()  
  {
   Print("Пришёл новый тик");
   int total=OrdersTotal();
   Print("Всего ордеров = "+total);
   for (int i=0;i<total;i++)
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
         //Print("Всего ордеров = "+OrdersTotal());
         Print("удаляем ордер = "+i+" тикет ордера = "+OrderTicket());
         while(IsTradeContextBusy())
            {
            Print("Торговый поток занят");
            Sleep(100);
            }
         RefreshRates();       
         OrderClose(OrderTicket(),OrderLots(),Bid,100,0);
         Print("ошибка="+GetLastError());
         }  
   return(0);
  }
       

here is the EA log:

17:16:59 temp EURUSD,M1: loaded successfully
17:17:51 temp EURUSD,M1: New tick arrived
17:17:51 temp EURUSD,M1: Total orders = 4
17:17:51 temp EURUSD,M1: delete order = 0 tick order = 2808657
17:17:52 temp EURUSD,M1: close #2808657 buy 1.00 EURUSD at 1.28969 at price 1.28973
17:17:52 temp EURUSD,M1: error=0
17:17:52 temp EURUSD,M1: remove order = 1 ticket order = 2808659
17:17:52 temp EURUSD,M1: close #2808659 buy 1.00 EURUSD at 1.28974 at price 1.28975
17:17:52 temp EURUSD,M1: Error=0
17:17:54 temp EURUSD,M1: New tick came
17:17:54 temp EURUSD,M1: Total orders = 2
17:17:54 temp EURUSD,M1: remove order = 0 tick order = 2808658
17:17:54 temp EURUSD,M1: close #2808658 buy 1.00 EURUSD at 1.28969 at price 1.28976
17:17:54 temp EURUSD,M1: Error=0
17:17:56 temp EURUSD,M1: New tick came
17:17:56 temp EURUSD,M1: Total orders = 1
17:17:56 temp EURUSD,M1: remove order = 0 tick order = 2808660
17:17:56 temp EURUSD,M1: close #2808660 buy 1.00 EURUSD at 1.28976 at price 1.28977
17:17:56 temp EURUSD,M1: error=0

 

Unfold the loop :

for(i=OrdersTotal()-1;i>=0;i--){
 
FAQ:

Unfold the loop :

Thank you, it works. What is the reason for this logic? I understand that something happens to the numbering of orders after they are called and deleted, but I don't understand exactly what it is yet.
 
Desead:
Thank you, it works. And what is the reason for this logic? I understand that something happens with numbering of orders after they have been opened and deleted, but I still don't understand exactly what it is.

You have four orders.

The cycle has started.

i = 0. Select a zero order. We delete zero orders, leaving 3 orders.

Check. Now there are 3 orders, i = 0 < 3. Go to the second cycle

i = 1. Select the first order. Delete the first order, and there are 2 orders left.

Check. Now there are 2 orders, i = 1 < 2. Go to the third loop

i = 2. We select the second order. And we have only 2 (that is, the de facto third order out of the two). OrderSelect will return false

i = 3. Select the third order. And we have only 2 (i.e. de facto the fourth order of two). OrderSelect will return false

 
ilunga:

You have four orders.

The cycle has started.

i = 0. Select a zero order. We delete zero orders, leaving 3 orders.

Check. Now there are 3 orders, i = 0 < 3. Go to the second cycle

i = 1. Select the first order. Delete the first order, and there are 2 orders left.

Check. Now there are 2 orders, i = 1 < 2. Go to the third loop

i = 2. We select the second order. And we have only 2 (that is, the de facto third order out of the two). OrderSelect will return false

i = 3. Select the third order. And we have only 2 (i.e. de facto the fourth order of two). OrderSelect will return false

Okay, thanks, I got it.)
 

Can you tell me the simplest Expert Advisor SMA (SMA line crossing the price) so I need it to open only on the closure of the candle at the crossover.

 
Vinin:

And why should it open orders, especially if the story is blank. I don't like editing other people's posts.
I'm a newbie, i can't get it right away. i will correct myself! If there are no orders OrdersHistoryTotal()==0i have already prescribed the condition to open orders, or am i confusing something!? i am not asking to edit the code, point out the error or give me directions so i can figure it out...! if you do not mind, thank you!
 
lowech:
I'm a newbie, I can't get it all at once . I'll correct myself! If there are no orders OrdersHistoryTotal()==0the condition to open, I prescribed it! Or am I mixing something up!? I'm not asking to edit the code, point out the error or give directions so I can figure it out ...! if you don't mind ...thanks!


If there are no orders in the history, a new order will never be opened. I replied back the first time

 

Is there a limit to the number of parameters in a non-standard indicator, when connected via iCustom?

I have an indicator with about 8 parameters, I entered all the parameters correctly, I checked it several times, but at compilation error ')' still appears - wrong parameters count D:\InstaTrader\experts\Expert_2.mq4 (11, 280)

 
Good day to all!Can someone advise how to write the following: for example, the time is now 13:00, just closed a candle in the H1 chart at 12:00, here is how to place an pending order for a 12 hour candle, the following parameters, if OPEN > CLOSE and the distance from OPEN to LOW is more than 12 pips then the order would be put on a buy with the following parameters buy price equal to the distance from OPEN to LOW and vice versa if OPEN < CLOSE and distance from OPEN to HIGH is more than 12 points then the order would be put to sell with the following parameters buy price equal to the distance from OPEN to HIGH...would very much appreciate help in writing...
Reason: