order placement

 

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, 

 
Check if you have an order open before opening.
 
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;
            }
      }
 
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.

Reason: