Any EA's that OPEN/CLOSE more than 1position?

To add comments, please log in or register
skorcht
60
skorcht  

I'm just looking for an example of an EA that opens and closes more than 1 position at a time..

THANKS

. ... Rick D. ... .
1167
. ... Rick D. ... .  

The following code closes all the opened long and short positions.

int Slippage = 3;

void CloseOrders() {

int cnt = OrdersTotal();

for (int i=cnt-1; i>=0; i--) {

if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

//if (OrderSymbol() != Symbol()) continue;

//if (OrderMagicNumber() != Magic) continue;

if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, Slippage);

if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, Slippage);

}

}
skorcht
60
skorcht  

sweet..

that Helps!

skorcht
60
skorcht  

This is the code that the EA GENERATOR created for closing open positions(down below)

The problem is that because of whatever reason..both positions are not getting closed all the time when the conditions are right.

maybe it's timing with broker, I don't know.

SO, if this code is Correct...instead of doing it this way...

can it be written LIKE-

WHILE OrdersTotal() > 0

CLose all BUYS or

CLOSE all SELLS

It would SEEM that this would keep looping and trying to close all orders until there were none left before proceeding..

Is this Doable?

Present close code below

"bool IsTradeopen = False;

Total = OrdersTotal();

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

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

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

IsTradeopen = True;

if(OrderType() == OP_BUY) {

if (CloseBuy1_1 <= CloseBuy1_2 && CloseBuy2_1 < CloseBuy2_2 && CloseBuy3_1 < CloseBuy3_2) Order = SIGNAL_CLOSEBUY;

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

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

if (!EachTickMode) BarCount = Bars;

IsTradeopen = False;

Sleep(150);

}

else {

if (CloseSell1_1 >= CloseSell1_2 && CloseSell2_1 > CloseSell2_2 && CloseSell3_1 > CloseSell3_2) Order = SIGNAL_CLOSESELL;

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

OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

if (!EachTickMode) BarCount = Bars;

IsTradeopen = False;

Sleep(150);

}

}

}

}

"

cockeyedcowboy
524
cockeyedcowboy  

The reason that both positions are not getting filled is you need to program a delay between sending orders ( 10 seconds ) or your secondary orders will just time out. the loop you refer too can be program it into a your order routine, but if the order is not getting filled because of an error your EA will get locked into that loop not a good programing answer to the problem. Instead use the sleep() function to put a delay in your order execution routine. Also remember that if your running two EAs at the same time weather there are the same EA on different currencies or different EAs on the same currency or any combinations of EAs and currencies on the same account. You can still have this time out problem if any two EAs are trying to place orders at the same time on the same account. To get around this you should code your order entry routines to check if your account is being used first, if not then the routine should lock the account for its use only preventing other EAs from forceing orders between yours. After placeing an order you should program an 10 second delay. once all your orders have been placed you should verify that in fact they were executed before releaseing the account for other EAs to use.

skorcht:
This is the code that the EA GENERATOR created for closing open positions(down below)

The problem is that because of whatever reason..both positions are not getting closed all the time when the conditions are right.

maybe it's timing with broker, I don't know.

SO, if this code is Correct...instead of doing it this way...

can it be written LIKE-

WHILE OrdersTotal() > 0

CLose all BUYS or

CLOSE all SELLS

It would SEEM that this would keep looping and trying to close all orders until there were none left before proceeding..

Is this Doable?

Present close code below

"bool IsTradeopen = False;

Total = OrdersTotal();

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

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

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

IsTradeopen = True;

if(OrderType() == OP_BUY) {

if (CloseBuy1_1 <= CloseBuy1_2 && CloseBuy2_1 < CloseBuy2_2 && CloseBuy3_1 < CloseBuy3_2) Order = SIGNAL_CLOSEBUY;

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

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

if (!EachTickMode) BarCount = Bars;

IsTradeopen = False;

Sleep(150);

}

else {

if (CloseSell1_1 >= CloseSell1_2 && CloseSell2_1 > CloseSell2_2 && CloseSell3_1 > CloseSell3_2) Order = SIGNAL_CLOSESELL;

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

OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

if (!EachTickMode) BarCount = Bars;

IsTradeopen = False;

Sleep(150);

}

}

}

}

"
skorcht
60
skorcht  

That's interesting..i kinda thought it was a Timing issue with the broker but i only put a 150 MILLISECOND sleep time between orders. It SEEMS like I'm not having problems placing 2 ORDERS immediatley with NO delay between sends.

But I AM having problems getting both orders CLOSED on the close of the same bar (like they are suppose to)

A Question i had is when you CLOSE 2 orders...

WHen you do orderstotal() and you do For( int I...

and then CLOSE 1 open position, does that affect the "OrderSelect(i, "

meaning you HAD 2 orders, after one got closed your 'i' gets incremented to '1' but there's 1 order left does THAT remaining order turn into Order '0'?

does This QUestion makes sense?

and the EA "UniversalMACrossEA" lets you choose how many Retries for placing an order which tells me if there is an Error it will keep trying right?

And I'll be only using ONE EA on ONE chart..so I won't get into that other problem

Thanks COWBOY

cockeyedcowboy:
The reason that both positions are not getting filled is you need to program a delay between sending orders ( 10 seconds ) or your secondary orders will just time out. the loop you refer too can be program it into a your order routine, but if the order is not getting filled because of an error your EA will get locked into that loop not a good programing answer to the problem. Instead use the sleep() function to put a delay in your order execution routine. Also remember that if your running two EAs at the same time weather there are the same EA on different currencies or different EAs on the same currency or any combinations of EAs and currencies on the same account. You can still have this time out problem if any two EAs are trying to place orders at the same time on the same account. To get around this you should code your order entry routines to check if your account is being used first, if not then the routine should lock the account for its use only preventing other EAs from forceing orders between yours. After placeing an order you should program an 10 second delay. once all your orders have been placed you should verify that in fact they were executed before releaseing the account for other EAs to use.
cockeyedcowboy
524
cockeyedcowboy  
To add comments, please log in or register