How to Run EA just for One time

To add comments, please log in or register
errabbaa
19
errabbaa  

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 ?

Fabio Cavalloni
5025
Fabio Cavalloni  
You can check in orderhistory if already exists an order with that specific open order price.
errabbaa
19
errabbaa  
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  :-)

Lachlan Meakin
280
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.

errabbaa
19
errabbaa  
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
Keith Watford
Moderator
20997
Keith Watford  
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.

Enrique Dangeroux
682
Enrique Dangeroux  
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.

Fabio Cavalloni
5025
Fabio Cavalloni  
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.

Enrique Dangeroux
682
Enrique Dangeroux  
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.

Keith Watford
Moderator
20997
Keith Watford  
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

Lachlan Meakin
280
Lachlan Meakin  
Enrique Dangeroux:

Doubles are rarely equal.

True.

Bid >= Level

Would be better for a Sell limit.

Bid <= Level

For a Sell Stop

To add comments, please log in or register