How to stop EA from placing multiple trades.

 

Summary of Problem/background:

I am trying to place a buy stop order when the price hits a certain price, but I only want this to happen once, however I keep producing pending orders.


For example if on "EURUSD" , the price reaches 1.06700 and then places a buy stop at 1.06725. How do I ensure this only happens once through the coding, as the problem I am experiencing is that

it keeps producing orders every time it touches 1.06700.


I am new at coding so any help would be much appreciated.


Kind Regards,

Momo

 
  1. Check whether an open position already exists (magicNo. & symbol) or
  2. allow another order only for an opposite order (flag for next order buy or sell)
  3. allow another order after defined timespan
 

Hi,

Sorry to ask, but I'm not too sure what magic numbers are and how to use them, (they have always confused me). What do you mean by flag for next order?

with no. 3 (allow another order after defined timespan), do you mean using the Sleep () function after typing the Ordersend () Function.


Kind Regards,

Momo

 
Well, you'd better start to study existing eas, what they do and how they do it, and/or the articles about how to write EAs
 
MagicNumber: "Magic" Identifier of the Order
MagicNumber: "Magic" Identifier of the Order
  • 2006.07.24
  • Andrey Khatimlianskii
  • www.mql5.com
The article deals with the problem of conflict-free trading of several experts on the same МТ 4 Client Terminal. It "teaches" the expert to manage only "its own" orders without modifying or closing "someone else's" positions (opened manually or by other experts). The article was written for users who have basic skills of working with the terminal and programming in MQL 4.
 
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
Reason: