MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Read the Documentation. It is too Informative to be Ignored

Closing Multiple Trades at once

Back to topics list To post a new topic, please log in or register
avatar
11
isaacarsenal 2010.04.14 19:12
 

Is there any way to close all buy/sell trades at once?

There is a "Multiple Close By" feature in N2Trader which can close all buys/sells alternatively until all trades be closed or just one trade (which there are no pair trade for closing it) remains:





At first, i thought N2Trader uses the "Close By" method iteratively to close all trades. but it seems it's not the case, because:

- N2Trader do this significantly fast
- as shown below, the log distinguish between "close by" and multiple close".

all this things suggest that THERE IS a multiple close! But how i can do this in programatically (in MQL4 language) by a EA?





The log of a "Close by" order for two trades (a buy is closed by a sell):




The log of a "Multiple close" order:

 
Swedish company KnCMiner has discontinued the sales of its Bitcoin mining equipments
Swedish company KnCMiner has discontinued the sales of its Bitcoin mining equipments: "KnCMiner will change the Bitcoin industry by offering high performance mining products in combination with services that together make it extremely easy and cost efficient to mine Bitcoins in the future." It will focus on expanding its data centers to mine Bitcoins and solve similar complex algorithms.
avatar
1151
jjc 2010.04.14 20:08 #
 
isaacarsenal:

[...] all this things suggest that THERE IS a multiple close! But how i can do this in programatically (in MQL4 language) by a EA?

You do use OrderCloseBy() in order to do a multiple-close. However, this is less than simple. You can only pair off two orders at a time (which creates a new order for any difference between them in lot size). To do a multiple close, you have to make repeated calls to OrderCloseBy(). But the speed shouldn't matter enormously; once your buys and sells net out to zero, your cash position should only be affected by movements in the spread, not movements in the price. Therefore, it generally won't matter (significantly) whether the closure is near-instantaneous as it is in the user interface, or somewhat slower in the automated version using repeated calls to OrderCloseBy().

However, the "close by" is only supported by some brokers. On the others, the user interface option is not available, and the OrderCloseBy() function does not work.

 
avatar
536
EADeveloper 2010.04.14 23:25 #
 
isaacarsenal wrote >>

Is there any way to close all buy/sell trades at once?

There is a "Multiple Close By" feature in N2Trader which can close all buys/sells alternatively until all trades be closed or just one trade (which there are no pair trade for closing it) remains:





At first, i thought N2Trader uses the "Close By" method iteratively to close all trades. but it seems it's not the case, because:

- N2Trader do this significantly fast
- as shown below, the log distinguish between "close by" and multiple close".

all this things suggest that THERE IS a multiple close! But how i can do this in programatically (in MQL4 language) by a EA?





The log of a "Close by" order for two trades (a buy is closed by a sell):




The log of a "Multiple close" order:


Example for Close All Sell from an EA

for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_SELL&&OrderSymbol() == Symbol())
{
if(OrderMagicNumber() == MagicN)
{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Digits),10,CLR_NONE);
Sleep(100);
}
}
}
 
avatar
1151
jjc 2010.04.15 03:43 #
 
EADeveloper:

Example for Close All Sell from an EA [...]

isaacarsenal is specifically asking about closing orders by pairing them off against each other, rather than simply closing each individual order separately - i.e. using OrderCloseBy() rather than OrderClose(). On brokers who support it, this usually saves money (spread) and executes faster.

 
avatar
11
avatar
536
EADeveloper 2010.04.15 13:50 #
 
isaacarsenal wrote >>

I know the OrderCloseBy() function which close pairs of orders. But it cannot close all orders at once.

Is there any function which closes all trades at once?


No, no ready function to close all pairs of orders. you only can loop throug the open orders, and close them according to your rules (Pair, MagicNumber, only buys, only sells)..
 
avatar
1151
jjc 2010.04.15 14:21 #
 
isaacarsenal:

I know the OrderCloseBy() function which close pairs of orders. But it cannot close all orders at once.

Is there any function which closes all trades at once?

No. As explained in my earlier response.

avatar
22
skt1977 2011.01.06 02:22 #
 
jjc:

No. As explained in my earlier response.

Can someone please help me with / point me to a pre-written piece of code that I can use to achieve multiple close by ?


sat

 
avatar
Moderator
2029
gordon 2011.01.06 09:46 #
 
skt1977:

Can someone please help me with / point me to a pre-written piece of code that I can use to achieve multiple close by ?

There's an example in the book -> http://book.mql4.com/trading/orderclose (in the middle of the page, under "Closing Opposite Orders").
 
Back to topics list  

To add comments, please log in or register