Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information
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.