Quick question about opening/closing multiple orders each bar

 

So I understand fully how orders, deals and positions work, but I got a question about an EA trading on multiple pairs.


My EA trades on multiple pairs, with ONE order on each pair each time, and several pairs traded simultaneously

now at each new bar, I want to close the positions that need closing, and then open new positions as per the strategy.


now I need to know when all the positions have been effectively closed, so that I know "how much" I can open on the same bar next.


let's say I have a $10,000 account, based on the margin I can open let's say 1 lot with leverage.

I don't want to open an order BEFORE all the orders that need to be closed are closed of course.

so i'm not sure how I can do that

do I just need to see if the number of Orders and Deals of Closing actions are zero ?


thanks


Jeff

Documentation on MQL5: Trade Functions / OrdersTotal
Documentation on MQL5: Trade Functions / OrdersTotal
  • www.mql5.com
Returns the number of current orders. Return Value Value of the int type. Note Do not confuse current pending orders with positions, which are also...
 
You should check your positions to be 0.

Anyway I can't see why is so important for you to free the margin before opening next trade, it can have sense only if you use all your free margin with each trade, but I'm sure you know how risky it can be.
 
Fabio Cavalloni #:
You should check your positions to be 0.

Anyway I can't see why is so important for you to free the margin before opening next trade, it can have sense only if you use all your free margin with each trade, but I'm sure you know how risky it can be.

oh yeah I can store in a  buffer all the pairs that need closing at the opening of the bar, and then check the Positions to see if they are still there

i'll do that. Or even when ONE trade has been closed, I can open a new one, etc

the problem is that it's not all instantaneous, there can be delays in the opening/closing


I don't necessarily use all the margin, but I could use a fraction let's say 30% of the margin, and then open orders as per the amount.


let's say I have 1.4 lots to open orders, now I have 6 signals to open new orders. I'll open orders until 1.4 lots has been reached

or I could divide 1.4 by 6, and open all the orders that way, I'm not sure

 

Yes, delays are normal due to market operations that can take more or less time due to a lot of different factors...

You can consider to add a check of positions amount or free margin inside the conditions block that generate the trade opening action.

Based on how your EA is made, you should understand how to make it working correctly

 
Fabio Cavalloni #:

Yes, delays are normal due to market operations that can take more or less time due to a lot of different factors...

You can consider to add a check of positions amount or free margin inside the conditions block that generate the trade opening action, you should consider, based on how your EA is made, how to make it working correctly

yeah


also I use ATR to select the position size. so I need to determine what's the biggest lot per pair I can use, because I don't want to divide 1.4 by 2 orders only, I prefer open 2 orders and "maximum lot per pair" that's way I don 't get huge DD on 2 pairs only


let's say max volume per pair is 0.1

I got 1.4 lots to open.

1) I open 2 orders at 0.7 : there I get very high DD and the whole diversification is pointless now

2) I open 2 order at 0.1 : I got less profits, but the DD isn't through the roof.