Can't get EA to close 2 Open positions???

 

I have an EA that is suppose to close 2 open buys or sells when the conditions are right (one of the EA's functions)

I used the EA generator at that one website.

Anyways, it works alot of the time but sometimes it only closes 1 buy.

I even put in a short delay between closes because I thought it was a timing issue.

Is there a function to close ALL open buys or Sells in one shot? The Generator goes through 1 by 1 and closes them.

I can't think of why this won't close both all the time

 

Have fun.

skorcht:
I have an EA that is suppose to close 2 open buys or sells when the conditions are right (one of the EA's functions)

I used the EA generator at that one website.

Anyways, it works alot of the time but sometimes it only closes 1 buy.

I even put in a short delay between closes because I thought it was a timing issue.

Is there a function to close ALL open buys or Sells in one shot? The Generator goes through 1 by 1 and closes them.

I can't think of why this won't close both all the time

if (................Your condition to close the orders.................)

{

total = OrdersTotal();

for(int i=total-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type)

{

case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 1, Aqua ); break;

case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 1, Tomato );

}

if (UseSound) PlaySound(NameFileSoundClose);

}

}

Place this code at the end of the "int start()".

 

i should have posted the EA GENERATOR CODE..

it's almost the same as what you posted Yet I still have problems with both BUYS or SELLS not being closed at the same time..just 1 of them

for (int i = 0; i < Total; i ++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {

IsTrade = True;

if(OrderType() == OP_BUY) {

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage,MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continue;

ELSE --- the close sell code wich is same as close buy

 

Your problem maybe the way the loop is counted.

You have

for (int i = 0; i < Total; i ++)

It is a very poor style of coding, because the positions are renumbered as the first one gets deleted/closed. Thus, the last position will not get deleted/close.

Use the countdown method outlined by Roets...

total = OrdersTotal();

for(int i=total-1;i>=0;i--)

That is the right way to loop when trying to close/delete orders.

Good luck.

 

OK..

but why would it Not work only once in awhile?

Seems like it the COde was faulty..it wouldn't work every time.

i hate problems like thi

Reason: