Closing multiple orders and open opposite order

 

In my strategy to Start with ..

I can have one buy signal and after some time I can have one more buy signal.. it might continue up to 10 times.

Then when I get a sell signal, I need to close all the buy positions and open one sell position. Then the series of sell order may continue..

Basically, at one time, I have only one type orders (BUY or SELL).. but that can be 1 to many..

A) when I get signal for other order type, I need to close all the current open positions, if any.

B) When I get a signal for the same order type, I have to accumulate those orders.

It may be a piece of cake for some of you.. but for me not.. I need help on this.

1) If I use Ordercloseby - Does it close all the actvie orders and open another order against the current order ? if that is case, How do I give multiple ticket numbers to ordercloseby since I might have to close more than one order ?

2) Also, I may not be able to use Ordercloseby since my next order can be another order of same type position.. so I don't want to close the exisitng position but instead want to add to the current open orders..

Please.. your thoughts, ideas or snippets of code.. ?

 
OrderCloseBy() is used to close opposite orders, not orders of same type. You can open a new opposite orders that has a size equivalent to the total lot size of currently open orders plus the size of the new opposite order u want to open, then use a standard OrderCloseBy() loop to close all opposite orders (see code in section about OrderCloseBy() here -> https://book.mql4.com/trading/orderclose - it's about 2/3rd's down the page).
 
gordon wrote >>
OrderCloseBy() is used to close opposite orders, not orders of same type. You can open a new opposite orders that has a size equivalent to the total lot size of currently open orders plus the size of the new opposite order u want to open, then use a standard OrderCloseBy() loop to close all opposite orders (see code in section about OrderCloseBy() here -> https://book.mql4.com/trading/orderclose - it's about 2/3rd's down the page).


Thank you for the pointer.

I will study the code.

Using ordercloseby, I only want to close all the active orders BUT only want to open one order (not equivalent to the lot size of the closed orders) opposite to the active order. I will never have two types of orders at one time on the platfrom. I may have multiple lots of the same order type.

 
cprao:

Using ordercloseby, I only want to close all the active orders BUT only want to open one order (not equivalent to the lot size of the closed orders) opposite to the active order. I will never have two types of orders at one time on the platfrom. I may have multiple lots of the same order type.

If u can't hedge because of NFA rules, then OrderCloseBy() and the code I mentioned are irelevant to u...


If u are allowed to hedge, then my explanation does exatly what u want. I'll give a numerical example: let's say u have a few buy orders and their total lot size is 10. You want to close all buy orders and open 1 lots sell... So what u should do is open a sell order with lot size 11 and then run the OrderCloseBy() loop in the code I mentioned to close all opposite orders. When the loop is done you will have one sell order left with the size of 1 lots as needed.

 
gordon wrote >>

If u can't hedge because of NFA rules, then OrderCloseBy() and the code I mentioned are irelevant to u...


If u are allowed to hedge, then my explanation does exatly what u want. I'll give a numerical example: let's say u have a few buy orders and their total lot size is 10. You want to close all buy orders and open 1 lots sell... So what u should do is open a sell order with lot size 11 and then run the OrderCloseBy() loop in the code I mentioned to close all opposite orders. When the loop is done you will have one sell order left with the size of 1 lots as needed.


Ok.. Well thank you for the explanation.. In my situation - I am not allowed to hedge.

Your example is exactly applicable to my situation - I have to close all 10 buy orders and open only one sell order. So for this case, how do I code it ?

 
cprao:


Ok.. Well thank you for the explanation.. In my situation - I am not allowed to hedge.

Your example is exactly applicable to my situation - I have to close all 10 buy orders and open only one sell order. So for this case, how do I code it ?

If u can't hedge, u can't use OrderCloseBy(). Your only solution is a simple order closing loop... Once it's done, open the single opposite order. For code samples u can google 'close all orders'.
 
gordon wrote >>
If u can't hedge, u can't use OrderCloseBy(). Your only solution is a simple order closing loop... Once it's done, open the single opposite order. For code samples u can google 'close all orders'.

Ok. Cool. Thank you..
 

Hi,

Anyone have the EA for Closing multiple Order in one go

Reason: