Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
I've attached a code snippet below, which pairs up buys and sells and close them against each other. The point is that it really doesn't matter which ones you pair up, especially if they are all of the same lot size.
Ideally though, you should first compute the right amount of excess trades to close at current price, because the pairing up and closing takes some time, and the price might be moving while that happens; you would want to close the excess first, and thereafter the paired up ones.
One alternative could be to pair up and close the pairs earlier, at anytime after a positive state is achieved. Though then you will have to account for the balance change induced by the pairwise closing in the remaining cycle life until TS fires; the EA would have to pretend that the pairwise closing hasn't happened yet for the TS calculations and in trade counts etc. That is, if you want to actually close early, but mimic the behaviour as if not having closed.
PHP Code:
int buys[10000];
int sells[10000];
void ClosePairwise(int magic)
{
bool both = true;
while ( both ) {
int sp = 0;
int bp = 0;
both = false;
for ( int i = OrdersTotal() - 1; i >= 0; i-- ) {
if ( ! OrderSelect( i, SELECT_BY_POS ) )
continue;
if ( OrderMagicNumber() != magic )
continue;
if ( OrderType() == OP_BUY ) {
if ( sp < 1 ) {
buys[ bp ] = OrderTicket();
bp += 1;
continue;
}
both = true;
sp -= 1;
OrderCloseBy( sells[ sp ], OrderTicket(), Yellow );
} else if ( OrderType() == OP_SELL ) {
if ( bp < 1 ) {
sells[ sp ] = OrderTicket();
sp += 1;
continue;
}
both = true;
bp -= 1;
OrderCloseBy( buys[ bp ], OrderTicket(), Yellow );
}
}
}
}
I've attached a code snippet below, which pairs up buys and sells and close them against each other. The point is that it really doesn't matter which ones you pair up, especially if they are all of the same lot size.
Ideally though, you should first compute the right amount of excess trades to close at current price, because the pairing up and closing takes some time, and the price might be moving while that happens; you would want to close the excess first, and thereafter the paired up ones.
One alternative could be to pair up and close the pairs earlier, at anytime after a positive state is achieved. Though then you will have to account for the balance change induced by the pairwise closing in the remaining cycle life until TS fires; the EA would have to pretend that the pairwise closing hasn't happened yet for the TS calculations and in trade counts etc. That is, if you want to actually close early, but mimic the behaviour as if not having closed.
PHP Code:
int buys[10000];
int sells[10000];
void ClosePairwise(int magic)
{
bool both = true;
while ( both ) {
int sp = 0;
int bp = 0;
both = false;
for ( int i = OrdersTotal() - 1; i >= 0; i-- ) {
if ( ! OrderSelect( i, SELECT_BY_POS ) )
continue;
if ( OrderMagicNumber() != magic )
continue;
if ( OrderType() == OP_BUY ) {
if ( sp < 1 ) {
buys[ bp ] = OrderTicket();
bp += 1;
continue;
}
both = true;
sp -= 1;
OrderCloseBy( sells[ sp ], OrderTicket(), Yellow );
} else if ( OrderType() == OP_SELL ) {
if ( bp < 1 ) {
sells[ sp ] = OrderTicket();
sp += 1;
continue;
}
both = true;
bp -= 1;
OrderCloseBy( buys[ bp ], OrderTicket(), Yellow );
}
}
}
}
Thank you Ralph! I'll check this out and try to incorporate it. I really appreciate your help and contribution!
This will violate IBFX scalping rules and we will get flagged!
It is real and yes I guaranty it will happen for those of us at IBFX....with an EA with this many orders there will be too many "90 second duration and under", trades.
ES
Quote:
Originally Posted by kayvan
also we need 1 tp for every order and 1 tp for the remaining ordes.
Last edited by ElectricSavant; 03-04-2008 at 04:58 AM.