# Martingale EA - page 124

420

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.

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 ) {

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 );

}

}

}

}

[Deleted]

Just fricken genius...

Ralph...I would hate to think if you were a trader and treated Forex other than a hobby...

Excuse me for drooling over your code...

ES

1037

ralph.ronnquist:
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.

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 ) {

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!

Yet another time you have rescued me.

160

160

wolfe:
You're describing a coding NIGHTMARE here Kayvan!

sorry Wolfe , but it seem`s to be necessary for our EA.

[Deleted]

Why?..........They are working on WFM

kayvan:
sorry Wolfe , but it seem`s to be necessary for our EA.
1037

ElectricSavant:
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 too many 90 second duration and under trades.

ES

ES is right Kayvan, I'm sorry, but this is the truth. I'm not going to code something we cannot eventually trade live.

[Deleted]

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

kayvan:
also we need 1 tp for every order and 1 tp for the remaining ordes.
160

wolfe:
ES is right Kayvan, I'm sorry, but this is the truth. I'm not going to code something we cannot eventually trade live.

but this just ibfx rules !not the others .

i diden`t understand ralph method . maybe it would solve our problem. but i know we must do some thing. like 2 kind of TP

[Deleted]

kayvan,

Do you thinkl FXOpen and Master...will let you trade hundreds of orders per day at 1 pip TP...your dreaming...welcome to requotes and manual trading desks....

These dealers must have time to lay off your trades and you will be stopped or slowed down, because when you start cutting into their profits thay will do something about it.

Every dealer has the RIGHT to do business with who they want. Keep your dealer happy and play their crooked game kayvan.

I do not mean any disrespect to you, I am just telling you the way it is...ok?

ES

P.S. Give wolfe and Ralph a chance to get the "global close-all" to be VERY efficient.

kayvan:
but this just ibfx rules !not the others . i diden`t understand ralph method . maybe it would solve our problem. but i know we must do some thing