| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
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 |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 ![]() |
|
||||
|
Quote:
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()".
__________________
Pro FX Experts for Professional Meta Trader Experts Automate your manual method! We accept all major credit cards with no upfront payment required! |
|
|||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| EA to close positions after profit/loss hit | james2ko | Expert Advisors - Metatrader 4 | 1 | 05-22-2007 04:03 AM |
| Open/close trade on same bar's close? | WNW | Expert Advisors - Metatrader 4 | 2 | 03-29-2007 05:37 AM |
| Close all open positions | jonjonau | Expert Advisors - Metatrader 4 | 6 | 07-12-2006 05:01 AM |
| Close All Open Positions? | lonespruce | Metatrader 4 | 9 | 06-22-2006 07:20 AM |