| 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 |
|
|||
|
Closing Pending Orders
I'm having a problem with this EA. It is supposed to close all pending orders when a stop loss is modified, however, it is closing all my orders before the stop loss is being modified. Hence, I don't even know if the stop order modifications work correctly.
//+------------------------------------------------------------------+ //| Millionaire.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #include <stdlib.mqh> #include <WinUser32.mqh> extern double Price1; extern double HighPrice = 0; int start() { if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true) { Price1 = OrderOpenPrice(); if(Bid>HighPrice==true) { HighPrice = Bid; } { if(((HighPrice - OrderOpenPrice()) > (40 * Point)) && (OrderStopLoss() < (HighPrice - (20 * Point)))==true) { OrderModify( 0, OrderOpenPrice(), HighPrice - (20 * Point), HighPrice + (100 * Point), 0, CLR_NONE); int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close pending orders case OP_BUYLIMIT : case OP_BUYSTOP : case OP_SELLLIMIT : case OP_SELLSTOP : result = OrderDelete( OrderTicket() ); } if(result == false) { Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } } } } return(0); } |
|
||||
|
It looks to me like you have statements for closing orders IMMEDIATELY after the statements for modifying them, which would cause what you are getting. By the way, why are you trying to modify a stop AND THEN delete the order? Makes no sense to me. While we're thinking along these lines, I just made an EA that can modify stops and close orders. You can check it out below. Maybe it will help you, maybe it won't. At the very least, you can check the code as a programming example:
Swiss Army EA (Automatic order management)
__________________
"Don't work harder, work smarter." -- my Java professor Coder for Hire: http://www.firecell-fx.com |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Closing all orders EA? | InTrance | Expert Advisors - Metatrader 4 | 10 | 08-19-2007 01:13 AM |
| MT4 pending orders | fx_geezer | Metatrader 4 | 5 | 06-15-2007 09:36 PM |
| modify orders and close pending orders | bkgridley | Questions | 8 | 05-23-2007 09:49 PM |
| EA Help Needed - Closing Existing Orders | SuzanneFX | Metatrader 4 | 1 | 12-26-2006 02:28 PM |
| Pending orders | TheExponential | Questions | 4 | 11-25-2005 12:36 AM |