progressapama Posted January 24, 2009 Report Share Posted January 24, 2009 I am trying to write a small pending orders code . it simply closes a pending order if the parent order is a win and it should open a pending order if the parent is a LOSS. The code below works but it goes into a LOOP after a few iterations. Any Help on the Bottom part of the code. Thank you in advance :cry: int CheckOpenPendingOrders() { for (int i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderType() == OP_SELL || OrderType() == OP_BUY) if (StringSubstr(OrderComment(), 0, 4) == "Open") return (OrderTicket()); } } return (0); } int CheckPendingOrders() { for (int i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP || OrderType() == OP_BUYSTOP) if (StringSubstr(OrderComment(), 0, 4) == "Pending") return (OrderTicket()); } } return (0); } // The Below Code does not seem to work it goes into a LOOP after after a few trades. void ClosePendingOrders() { double PendingOrderOpenPrice; int ParentTicket; int PendingTicket = CheckPendingOrders(); int OpenPendingOrderTicket = CheckOpenPendingOrders(); if (PendingTicket > 0 ) //Scan to see if there exists pendings Orders that needs to be cancelled { OrderSelect(PendingTicket, SELECT_BY_TICKET); PendingOrderOpenPrice = OrderOpenPrice(); ParentTicket = OriginalOrderTicket(PendingTicket); OrderSelect(ParentTicket, SELECT_BY_TICKET); if (OrderCloseTime() > 0) { if (OrderProfit() <= 0.0 )return; // it should activate the Pending order ( into an open Sellstop or buystop) if the Parent order was a LOSS trade // i.e the STOP LOSS was hit // does not seem to work correctly it causes a LOOP. it is able to activate the pending order but // then it starts to go into LOOP OrderDelete(PendingTicket); // Deletes the Pending Order if the Parent order was a WIN if (!(Outcome)) return; return; } } } Quote Link to comment Share on other sites More sharing options...
collinsmith Posted January 24, 2009 Report Share Posted January 24, 2009 Re: [ Help Req] Please Help with this Pending Orders Code Hi progressapama, I did some thorough reading on your code but was unable to find the cause of problem. One possible reason could be errors from the return values of the customized functions or the MT4's functions. Suggestions: 1. Print out the variables values such as ParentTicket, PendingTicket and compared with the expected values during the forward test. 2. Print out the system errors for MT4's functions such as OrderSelect using the recommended GetLastError() and ErrorDescription() functions from MT4 documentations. This can be found in h**p://docs.mql4.com/constants/errors Hope this information helps. Regards, Collin Quote Link to comment Share on other sites More sharing options...
progressapama Posted January 25, 2009 Author Report Share Posted January 25, 2009 Re: [ Help Req] Please Help with this Pending Orders Code Thank you so much i think i figured out where the problem was occuring . Thank you :arrow: :peace: :shand: Quote Link to comment Share on other sites More sharing options...
tgt123 Posted January 27, 2009 Report Share Posted January 27, 2009 Re: [ Help Req] Please Help with this Pending Orders Code Thank you so much i think i figured out where the problem was occuring . Thank you :arrow: :peace: :shand: Hi Progressapama, we are very appreciated if you can share this pending order EA, attached is the EA maybe similiar to it, but it couldn't close all pending order or opened orders once 1 of the opended position hit profit! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.