MQL4 - automated forex trading   /  

Forum

VininI ConstTickHeikenAshi RIndicator
VininI ConstTickHeikenAshi R
Author: Vinin
Subscribe to signal
Automatic cashflow
16.60%, 469.71 USD
Screenshot
EURUSD-, H1
Demo
Quest Candlestick patterns indicatorQuest Candlestick patterns indicator Try product
Quest Candlestick patterns indicator
Author: codeidea
All about Automated Trading Championship: Reporting the Championship 2007All about Automated Trading Championship: Reporting the Championship 2007

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:

 
All about Automated Trading Championship: Interviews with the Participants'07

All about Automated Trading Championship: Interviews with the Participants'07

The published interviews of Championship 2007 bear the stamp of the results obtained during the preceding contest. The first Championship evoked a wide response on the internet and in printings. The leading developer of the MetaQuotes Software Corp. tells about changes made to the forthcoming Automated Trading Championship 2007. We put our questions to the developer of a well-known indicating complex ZUP, Eugeni Neumoin (nen) and spoke to an equity trader, Alexander Pozdnishev (AlexSilver).


avatar
1139
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
538
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
1139
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
538
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
1139
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
20
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
2032
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