Total Orders Count both Pending order and running trades
-
I want my ea to be able to count all the existing orders, both trades and pending order. Then close all trades and delete all pending orders if their total number is less than an input value
Say for instance input value for total orders = 30, if trades is 6 and pending order is 24 nothing happens
But if trade is 1 and pending order 19 for instance, they all close since it doesn't sum up to 30
Please I've been trying to do this for days






I need help -
Frustrating isn't it...?
Perhaps try something like this..>> https://fxdreema.com/shared/mpkxcGU0e
Note we are using both the On Tick and On Trade tabs....*
-
@COFX This is the second thread you created for the exact same question. Please don't duplicate threads.
-
@Morpheus_0 very frustrating indeed. Let me take a look at what you shared. I'll reply
-
@Morpheus_0 I don't understand many things there... First the formula, then the on trade events but let me start with the formula
How does the ea tell that the variable, Trade means total number of trades and that the variable Orders means total number of pending orders? This is where the basis of my confusion is
-
Hello.
Here is a working and validated example EA.
Since I don't know the condition less than 30, I simply used greater than 30 in the system.
Please run it once in the visual strategy tester.
There you can see that all 30 trades (pending and open) are closed.
Greetings
Lacone
Test2.mq5 -
@Lacone please how can I define a variable? Like is I want to define a variable to count all running trades and another to count all running orders. And my ea is MT4
-
@COFX said:
How does the ea tell that the variable, Trade means total number of trades and that the variable Orders means total number of pending orders?
On Trade tab>
Trade Created updates the number of trades variable
Order Created updates the number of orders variable.
Sum is the sum of the two.The other two blocks should reset the variables to 0 when all the trades and orders are closed/deleted....*
-
@Lacone please share a project link
-
@COFX said:
please how can I define a variable?
Top left, click on Variables and create them there....*
-
@Morpheus_0 I've seen the variable but I still don't get it though.. when creating them is there a way I'll tell the ea that this variable means total open trades?
-
-
In the link I posted above^^...on the On Tick tab, the Formula adds them all up and puts them into the Sum Variable.
The condition block then says that the Sum has to be equal to or more than 30....*Actually, in the Condition block, you need to change the 'Equals or Above' to 'Equals or Below'...sry bout that...*
Not sure how you open more than 30 trades and orders at once though....*
-
@Morpheus_0 It's alright, I get the inequalities (less than or equal to). Still don't understand how you defined those variables (trades, orders) what is trades? Does the ea recognize trades to mean total open orders?
-
Every time a trade is created it updates the Trades Variable....*
-
o I'm beginning to see, but please can you say more?

-
@Morpheus_0 Thank you so much, it is becoming clearer and clearer now, however in the ontrade tab, if one trade just close, it modifies the variable to zero? should it not be only when all the trades close?
-
@Lacone Thank you, i'm taking a look at it now
-
@COFX said in Total Orders Count both Pending order and running trades:
@Morpheus_0 Thank you so much, it is becoming clearer and clearer now, however in the ontrade tab, if one trade just close, it modifies the variable to zero? should it not be only when all the trades close?
Yes you are correct, but the Close Trades block should close all running trades. Is that not what you want....?
-
A trade can close by stop loss (trailing stop) so only then, only when the trades are less than 30 should all trades close
But the variable should only be zero when there are no existing trades.. because the ea has two strategies. If the last closed trades had no stop loss modified (close by TP), then the ea would not do anything to existing orders... But if stop loss of last closed trade was modified and trades total is less than 30, then everything but running trades and pending order gets closed... Only then should the variable reset to 0.
There's a block, trades count and another pending order count, is there a way to use the results from these blocks in a formula?