Loops and Closing or Deleting Orders - page 4

 
ggekko:

Hi experts, what is your opinion about this solution?

while(OrdersTotal()>0)
It means it is incompatible with every other EA (including itself) and manual trading. (Trades on other charts)
 
WHRoeder:
ggekko:

Hi experts, what is your opinion about this solution?

It means it is incompatible with every other EA (including itself) and manual trading. (Trades on other charts)

Of course. This is a total close all.

Sometimes there are situations (for example you want to close too many open trades immediately) when the "original" version doesn't work. This version is good for this.

 
ggekko:

Of course. This is a total close all.

Sometimes there are situations (for example you want to close too many open trades immediately) when the "original" version doesn't work. This version is good for this.

Why aren't you attempting to react to errors ? shouldn't you analyse the error and react accordingly ?  for some errors you can retry,  for others you have to stop trying.
 

Hi,


I have a question about while loops. I want to run the current EA on a loop as frequent as possible. So, my thought is to put the current code inside a while loop with a sleep function included inside that causes the while to only execute every 1 millisecond.


However, when I did this, (I have some Print("...") function calls put in which keeps track of what's happening on each loop), I see this freezing, and no more prints to the screen.

I'm wondering what the problem might be. Is it ok to run the EA on a loop as frequent as 1ms? Would there be an issue with trying to obtain the latest bid/ask for example from the server every millisecond? Would this put too much load there, causing the freeze?

Possibly something else my algorithm is doing is causing this, I'm not sure.


I have ran it on 200ms cycles and still get the same problem (though just not as immediate). Could there be an issue with printing too many lines to the log file?



thanks for any advice on this.

regards,


C.

 
Can be a code problem - but without knowing the code?
 

14967057:

I have a question about while loops. I want to run the current EA on a loop as frequent as possible.

So, my thought is to put the current code inside a while loop with a sleep function included inside that causes the while to only execute every 1 millisecond.

Would there be an issue with trying to obtain the latest bid/ask.

Could there be an issue with printing too many lines to the log file?

  1. This thread was about Closing and Deleting orders. Don't hijack threads for off topic questions. Post a new one.
  2. Why do you want to continuously loop? Nothing is changing. All you are doing is wasting CPU time. 
  3. Return from start and when Bid/Ask changes, your start will be called as fast as possible.
  4. Yes, you've filled all available ram with the lines, faster than Windows can put them to disk. All programs get paged out. Everything hangs.
 

Hi,

Turns out, the problem I had was not due to encapsulating my EA code inside a while loop with a 1ms sleep. This part seems fine (regardless of where I print to screen or not) as I have it running now for the last half hour without fault.


The problem was due to another sneaky while I had in the code which eventually caused the EA to get trapped in an infinite loop.

Thanks for the input gooly and Roesder.

regards,

 

Hello everybody. I read this topic and I have question. I try to make a code, which delete pending order (only STOP, no LIMIT), but only if another pending order was activated (start be OP_SELL or OP_BUY). So code is this (but there are a mistakes, but I don´t know where). Could you look at my code please? 

 

 bool   result;
   int   i, j, cmd, cmd2,total;

   total=OrdersTotal();

   for(i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         cmd=OrderType();
         
         if(cmd!=OP_BUYSTOP && cmd!=OP_SELLSTOP)  //take an orders which was activated 
           {
           for(j=0; j<total; j++)   //another variable j 
     { 
     if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)){ cmd2=OrderType();
     if(cmd2!=OP_BUY && cmd2!=OP_SELL)
           {
            
            OrderPrint();
            
            result=OrderDelete(OrderTicket());  //first pending order become to OP_SELL or OP_BUY, second pending order will be delete
            if(result!=TRUE) Print("LastError = ", GetLastError());
            break;
           }
        }
       }
     }
     }
   }
 

OrdersTotal() not correct...

I have been surprised by looping code sequence which uses OrdersTotal() not giving correct results (observed with two different brokers). 

I am using MT4 version 1090 on a Linux Ubuntu-MATE 16.04 desktop, running WINE 3.0

Here is what I have been using...

for(int cc = 0; cc < OrdersTotal(); cc++)
{
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;
      if (OrderSymbol() != Symbol() ) continue;
      if (OrderType() > 1) continue;    //--ignore pending trades

      OpenTradecnt++;    //--counts up for every live position of that symbol that exists
      Print("count of the open trades of this symbol is: ", OpenTradecnt);
}

I have noticed with two different brokers that the OrdersTotal() value does not always agree with what is shown in the 'Trade' tab of the MT4 broker.  Initially, I thought that it was the broker causing OrdersTotal() to not function properly.  When I noticed on the 2nd broker, I began to wonder if MT4 had an internal 'issue', or if my code was wrong OR if this was a problem with MT4 properly synchronizing with the server....?

After reading this forum thread, I wonder if I would have a change in results to change the for..loop to read:

for(int cc = OrdersTotal() - 1; cc >= 0; cc--)
{
     ...........
}

OR, is there a flag or line of code that will ensure that the OrdersTotal() is properly synchronized during an OnTick() event?

Any clarification regarding this would be very helpful and would be greatly appreciated!

 

Please use the </> button to insert your code.


Reason: