How to Run EA just for One time

 

Hello,

I'm coding an EA that opens orders with TP and SL when a price is hit.

I don't want the EA to reopen any other orders if the same price is hit a second time.

how can i control that ?

 
You can check in orderhistory if already exists an order with that specific open order price.
 
Fabio Cavalloni:
You can check in orderhistory if already exists an order with that specific open order price


Thanks for ur replay,

can you give me an example of code ? i'm a newer in mql community  :-)

 

How may of these entry price levels do you have?


An easier way would just be to use a boolean variable to check if that level has been traded or not


double level = 0.7867; // or whatever price you want to enter
bool levelTraded = false;

if (!levelTraded && Bid == level) 
   {
   OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0,"level traded",123456,0,clrBlue);
   levelTraded = true;
   }


It will only trade at that level once, until you restart the EA.

 
Lachlan Meakin:

How may of these entry price levels do you have?


An easier way would just be to use a boolean variable to check if that level has been traded or not



It will only trade at that level once, until you restart the EA.

thank u so much, will try and give u a feedback
 
Fabio Cavalloni:
You can check in orderhistory if already exists an order with that specific open order price.

Because of slippage, an order may not have been opened at the exact price.

 
Lachlan Meakin:

How may of these entry price levels do you have?


An easier way would just be to use a boolean variable to check if that level has been traded or not


double level = 0.7867; // or whatever price you want to enter
bool levelTraded = false;

if (!levelTraded && Bid == level) 
   {
   OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0,"level traded",123456,0,clrBlue);
   levelTraded = true;
   }

It will only trade at that level once, until you restart the EA.

Doubles are rarely equal.

 
Keith Watford:

Because of slippage, an order may not have been opened at the exact price.

Of course it's mandatory to declare an amount of tolerance points because also 2 pending orders placed at the same price can be executed with some points of difference.

 
Keith Watford:

Because of slippage, an order may not have been opened at the exact price.

True, but MT5 it is possible to check with requested price in history.

 
Enrique Dangeroux:

True, but MT5 it is possible to check with requested price in history.

Thanks, I didn't realise that. I'm still not so hot with MQL5

 
Enrique Dangeroux:

Doubles are rarely equal.

True.

Bid >= Level

Would be better for a Sell limit.

Bid <= Level

For a Sell Stop

Reason: