tt.aa: Could anyone one please teach me how to control the number of the opened trades in my EA ? (please have a look on my code below)
-
Why did you post your MT4 question in the
Root /
MT5 EA section
instead of the
MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - Your first if/if says fast above slow and no open orders, open a buy. The third if/if says fast above slow and at least one open order, open another buy. Stop opening orders if there is already one open. Delete the third and fourth.
Hi
here is the probleme with your code
if (Orderscnt ()> 0 )// for any future buy order
that s mean the expert after checking conditions for buy or sell, will opens many, many others orders (maximum orders that broker allows)
Solution is simple :
change it to
if (fastMA>slowMA)
if (Orderscnt()==1)// for any future buy order
int ticket_1 = OrderSend (Symbol(),OP_BUY,lot,Ask,30,0,0,NULL,magicno,0,clrGreen);
if (fastMA<slowMA)
if (Orderscnt()==1)// for any future sell order
int ticket_2 = OrderSend (Symbol(),OP_SELL,lot,Bid,30,0,0,NULL,magicno,0,clrRed);
}
In this way, Expert will open Just second Order and stop opening other orders.
good luck.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Could anyone one please teach me how to control the number of the opened trades in my EA ? (please have a look on my code below)
It is a 2 moving averages (not crossover) (it is above/below) using candle number 0, so when the fast MA is above the slow MA it opens a buy order straight away, and the opposite for sell.
I know it might open a lot of trades as I'm using candle number 0, but I'm only trying to learn how to control the number of opened trades that's all.
The problem is that the EA open trades on every tick,,,,,
but what I would like is for the EA to open only 1 trade for every time the conditions for buy/sell orders are met.
For example:
If the EA opened a 1 buy trade,
then the conditions are met for a sell trade then the EA should open 1 sell trade,
and if the conditions are met again for buy I would like the EA to add another buy trade, and so on.
I would appreciate any help.