Download MetaTrader 5
To add comments, please log in or register
Does your signal already have a lot of of subscribers? It's time to think about the paid subscription!
parham.trader
193
parham.trader 2015.10.09 14:58 

Hi friends,

I'm writing an expert advisor,

Can anyone help me what is the easiest way to prevent OnTick Function from placing orders repeatedly.

 I have some ideas in my mind but I think there would be easier ways to stop expert advisor from placing an order repeatedly in OnTick function and instead place only 1 order.

thanking in advance, 

whroeder1
13627
whroeder1 2015.10.09 20:39  
Check if you have an order open before opening.
Gabor Keresztessy
201
Gabor Keresztessy 2015.10.10 16:13  
parham.trader:

Hi friends,

I'm writing an expert advisor,

Can anyone help me what is the easiest way to prevent OnTick Function from placing orders repeatedly.

 I have some ideas in my mind but I think there would be easier ways to stop expert advisor from placing an order repeatedly in OnTick function and instead place only 1 order.

thanking in advance, 

Hi,

at live order checking needs to set true or false is there opened order or not, and if not the EA can open a new. I use this logic in my EAs.

for (counter1=OrdersTotal()-1; counter1>=0; counter1--) {
   if (OrderSelect(counter1,SELECT_BY_POS)==true) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic_number) {
         ...
         ...
         ...
         liveorder=true;
      break;
      } else {
         liveorder=false;
       }
.
..
...
//and here comes the open trade session, we open a sell
if (liveorder==false) { 
    ......
    while(true) {
         last_order_ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,20,Ask+order_sl,Ask-order_tp,"comment if you want",magic_number,0,clrWhite);
         Error_handling(GetLastError());
         if (last_order_ticket > 0) {
            break;
            }
      }
parham.trader
193
parham.trader 2015.10.10 20:15  
pecskeke1976:

Hi,

at live order checking needs to set true or false is there opened order or not, and if not the EA can open a new. I use this logic in my EAs.

Wow , what a great answer !

I exactly use the same logic in my own code , the only difference is that I also change the Symbol string into integer with my own logic and use it in the magic number.

By the way, thank you very much for your kind guidance.

/
To add comments, please log in or register