Loops and Closing or Deleting Orders

Back to topics list  | 1 2 3 4 To post a new topic, please log in or register
avatar
13006
WHRoeder 2014.09.23 17:04 #
 
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)
avatar
1218
ggekko 2014.09.23 18:46 #
 
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.

avatar
14167
RaptorUK 2014.09.23 19:59 #
 
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.
avatar
17
14967057 2015.02.02 14:23 #
 


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.



avatar
2017
gooly 2015.02.02 14:58 #
 
Can be a code problem - but without knowing the code?
avatar
13006
WHRoeder 2015.02.02 16:27 #
 

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.
avatar
17
14967057 2015.02.03 11:08 #
 


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,



avatar
1
kraliczech 2015.02.18 23:27 #
 

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;
           }
        }
       }
     }
     }
   }
Back to topics list   | 1 2 3 4  

To add comments, please log in or register