Need help on stopping EA to open another trade.

 
My EA opens 3 buy trades this way:

First buy trade opens at the market order

Second buy order opens at 5 pips lower then the opening price of the first order

Third buy order opens at 7 pips lower then the opening price of the first order

If I close any one of the trades while the other two trades are still open in my account, EA will automatically opens another trade if EA meets the conditions above.

I do not want my EA to open another trade to replace the closed order until all orders are closed.

Any solution? Thank you for your help.
 
Find out how many trades are open before you place another order . . . use OrdersTotal-1 to form a for loop then OrderSelect and filter by Symbol and Magic Number
 

Dear RaptorUK:


Thank you as always for your quick respond and help. Could you please show me an example considering the total number of open orders are always 3?

 
zaffrono:
My EA opens 3 buy trades this way:

First buy trade opens at the market order

Second buy order opens at 5 pips lower then the opening price of the first order

Third buy order opens at 7 pips lower then the opening price of the first order

A) If I close any one of the trades while the other two trades are still open in my account, EA will automatically opens another trade if EA meets the conditions above.

B) I do not want my EA to open another trade to replace the closed order until all orders are closed.

The two criteria marked A and B above seem logically contradictory. According to rule A, if the third buy becomes profitable and is closed it should be re-opened when the price dips 7 pips below the first buy. According to rule B you do nothing until all three orders are closed. I am confused.
 
zaffrono:
My EA opens 3 buy trades this way:

First buy trade opens at the market order

Second buy order opens at 5 pips lower then the opening price of the first order //can this With pending buylimit ?

Third buy order opens at 7 pips lower then the opening price of the first order //can this With pending buylimit ?

If I close any one of the trades while the other two trades are still open in my account, EA will automatically opens another trade if EA meets the conditions above.

I do not want my EA to open another trade to replace the closed order until all orders are closed.

Any solution? Thank you for your help.

bool tradeallowed = false;

//check your open trades
......


if (buy orders_this_EA==3)tradeallowed =false;
if (buy orders_this_EA==0)tradeallowed =true;
 
dabbler:
The two criteria marked A and B above seem logically contradictory. According to rule A, if the third buy becomes profitable and is closed it should be re-opened when the price dips 7 pips below the first buy. According to rule B you do nothing until all three orders are closed. I am confused.

Dear Dabbler:


Thank you for your consideration and question. Please just look at the situation this way: If 3 orders are opened and all of them closed at the same TP or STop loss then there is no problem and EA will not open any trade. However, while the 3 trades are open if I close one of them manually then EA will open one again to maintain the number of open trades as 3.

 
deVries:


Thank you DeVries for your solution. However, I am new in MQL4. Can you be please more specific or give more example?
 
More Specific.... How do you count your trades in your EA ?
 
zaffrono:Thank you for your consideration and question. Please just look at the situation this way: If 3 orders are opened and all of them closed at the same TP or STop loss then there is no problem and EA will not open any trade. However, while the 3 trades are open if I close one of them manually then EA will open one again to maintain the number of open trades as 3.

Coding is a logical process and one does have to understand exactly what one wants to do in order to code it. I am sure you understand what you want, but it is not quite clear to me yet. Never mind, you are going to be coding it!

We want to help you to learn to program it, rather than do it for you. Raptor has given you the starting point, so let's start from there. Show us how you are going to count how many open orders there are for this chart's symbol and this EA's magic number. Post your first effort even, if it doesn't seem to work. (Use the SRC button to post the code.)

You will need to use:

OrdersTotal()

OrderSelect()

OrderMagicNumber()

Symbol()

There are plenty of examples in the book

https://book.mql4.com//

 
Thank you guys for your quick respond and help. However, I am still lost.
 
zaffrono:
Thank you guys for your quick respond and help. However, I am still lost.

There is a good reason for that. We are trying to help you beyond your level. The idea of using Symbol() and OrderMagicNumber is too advanced for a total beginner. These are things you will need to learn, but you can do them later. For now we can just think of your EA running on its own with no other EAs or traders interfering with that account. Then you can skip the Symbol and the OrderMagicNumber for right now.

I am going to guess that you have no experience with any sort of programming. That makes a hell of a difference to how we approach the problem of getting you to understand things. Is my guess true?