-
Play videoPlease edit your post.
For large amounts of code, attach it.
- "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
- Solution ONE: If you select by ticket, you must test to see if the order has closed.
- SOLUTION TWO: If you select by position (MODE_TRADES), you will not find a closed trade.
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- "Doesn't work" is meaningless - just like saying the car doesn't work.Doesn't start, won't go in gear, no electrical, missing the key, flattires - meaningless. There are no mind readers here.
- Solution ONE: If you select by ticket, you must test to see if the order has closed.
- SOLUTION TWO: If you select by position (MODE_TRADES), you will not find a closed trade.
In regards to your #2 list, try re-reading everything posted. Just looking at "doesn't work" doesn't work, because right above that line, OP said what he was trying to do .
"EDIT:
Having same problem with closed Orders. Once one of my Orders hits a TP or SL -- I want all other orders (Pending and Activated) to be Cancelled/Closed. I've got the
custom function to shut them down. But again, I totally don't understand how to get my OrderSelect loop to detect if an Order is closed.....
if(OrderCloseTime() > 0) does not work "
It could be taken to mean that the code of "if(OrderCloseTime() > )" does not get his "OrderSelect loop to detect if an Order is closed" since that is what was stated here.
In regards to your #2 list, try re-reading everything posted. Just looking at "doesn't work" doesn't work, because right above that line, OP said what he was trying to do .
"EDIT:
Having same problem with closed Orders. Once one of myOrders hits a TP or SL -- I want all other orders (Pending andActivated) to be Cancelled/Closed. I've got the
custom functionto shut them down. But again, I totally don't understand how to get myOrderSelect loop to detect if an Order is closed.....
if(OrderCloseTime() > 0) does not work "
It could be taken to mean that the code of "if(OrderCloseTime() > )" does not get his "OrderSelect loop to detect if an Order is closed" since that is what was stated here.
As WHRoeder has already posted
SOLUTION TWO: If you select by position (MODE_TRADES), you will not find a closed trade.
How can you expect to find a closed order when looping through open orders?
Gum, my point was that WH posting his standard "this part covers everything" response like that was not a completely correct response to the question as it was posted. Him posting "saying does not work is meaningless" when the person DID actually say what wasn't working is as meaningless as he thinks the person saying only "doesn't work" was. The rest of it was as accurate as he usually is. I have never doubted his knowledge on coding in regards to MQL. His ability to deal with people leaves a little to be desired sometimes.
Edit: Sorry for getting off topic and taking away from the original idea for this thread, but felt this had to be said.
#0 - Sorry for being a Dummy and not posting code. Of course you need to see it.
Problem #1 (Detecting when Pending becomes Market) = Resolved (with Code Below)
Problem #2 = Determining when any Order has been closed = Not Resolved (see code Below)
#2a) Objective: Whenever Any (TP or SL) for Any Position gets hit - I'd like the EA to recognize that condition.
#2b) Y'all make a point that, By Looping through Open Orders (SELECT_BY_POSITION) --- obviously I shall never
detect a condition of OrderCloseTime() > 0. Any suggestions to resolve this puzzle?
.........................
There are tons of Closed Orders by this EA, I don't have to loop through all of them............. do I?
int start() { // LOCAL VARIABLES - START string Symb = Symbol(); int Magic_1 = Magic_Number + 1; int Magic_2 = Magic_Number + 2; int Magic_3 = Magic_Number + 3; int Magic_4 = Magic_Number + 4; int Magic_5 = Magic_Number + 5; //+-------------------------------------------------------------------+ //| ORDER ACCOUNTING | //+-------------------------------------------------------------------+ for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) == true && OrderSymbol() == Symbol() ) { //POSITION #1- ACCOUNTING if (OrderMagicNumber() == Magic_1) { //ORDER #1 - TP/SL Monitoring if(OrderCloseTime() > 0) // THIS IS THE PROBLEM! { Alert("711 : Position #1- TP/SL Hit - Closing All Positions"); Alert(" "); int Close_All = Position_Close_All(); EA_Terminate = true; return(0); } } // POSITION #1 = Market Order (no need to monitor for Activation) //POSITION #2- ACCOUNTING if (OrderMagicNumber() == Magic_2) { //POSITION #2- TP/SL Monitoring if(OrderCloseTime() > 0) { Alert("711 : Position #2 TP/SL Executed"); Alert("711 : EA Terminated - All Positions/Orders Closing"); Alert(" "); int Close_All = Position_Close_All(); EA_Terminate = true; return(0); } if(OrderType() < 2 && Order_Level == 1.5) { Alert("711 : Position #2- Pending Order Activated - initating Pending Order_3"); Alert(" "); Order_Level = 2; } } //POSITION #3- ACCOUNTING if (OrderMagicNumber() == Magic_3) { //POSITION #3- SL/TP Monitoring if(OrderCloseTime() > 0) { Alert("711 : Position #3- TP/SL Hit - Closing All Positions"); Alert(" "); int Close_All = Position_Close_All(); EA_Terminate = true; // Should BLOCK any further Orders getting executed... return(0); } if(OrderType() < 2 && Order_Level == 2.5) { Alert("711 : Position #3- Activated - initating Pending Position #4"); Alert(" "); Order_Level = 3; } } //POSITION #4- Accounting if (OrderMagicNumber() == Magic_4) { //ORDER #4 - TP/SL Hit - Close Out if(OrderCloseTime() > 0) { Alert("711 : Position #4- TP/SL Hit - Closing All Positions"); Alert(" "); int Close_All = Position_Close_All(); EA_Terminate = true; return(0); } if(OrderType() < 2 && Order_Level == 3.5) { Alert("711 : Position #4 - Activated - EA SHUT DOWN"); Alert(" "); Order_Level = 4; } } } if(Order_Level == 4) { EA_Terminate = true; Alert("711 : EA Terminated - Existing Orders Remain Valid"); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
EDIT: Thanks for your Responses so far. Please see my second post down yonder, where code is provided and situation narrative updated
Fully realizing this situation has been covered before, but wholly unable to comprehend the solutions provided. Hoping WHORIDER (sorry for spelling) or Raptor can rescue me.
FACTS
#1 Broker = Oanda (cause Oanda folks seem to have unique trouble with this)
#2 EA places 2 Pending Orders
#3 If ONE Pending order is ACTIVATED - I want the other Pending Orders to get cancelled.
In other words, I just want some basic OrderSelect() loop which is able to detect if a Pending Order has become a Market Order. Oanda assigns
a new Ticket#, so for sure the Original Ticket # will never change to OrderType < 2. Any Assistance much appreciated.
I've tried two solutions (listed below - both failed) ---
SOLUTION ONE = FAILED
Ticket_1 = 0 // global scope
Order_1_Active = false // global scope
if (OrderSelect(Ticket_1, SELECT_BY_TICKET) == true)
{
if(OrderType() < 2)
{
Order_1_Active = true;
}
}
.....
SOLUTION TWO = FAILED
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) //
if ( OrderSelect(pos, SELECT_BY_POS) == true && OrderSymbol() == Symbol() )
{
//ORDER 1 - Accounting
if (OrderMagicNumber() == Magic_1)
{
//ORDER #1 - TP/SL Hit - Close Out
if(OrderCloseTime() > 0)
{
Alert("711 : Trade_1 TP/SL Hit - Closing All Positions");
Alert(" ");
int Close_All = Position_Close_All();
EA_Terminate = true;
return(0);
}
}
EDIT:
Having same problem with closed Orders. Once one of my Orders hits a TP or SL -- I want all other orders (Pending and Activated) to be Cancelled/Closed. I've got the
custom function to shut them down. But again, I totally don't understand how to get my OrderSelect loop to detect if an Order is closed.....
if(OrderCloseTime() > 0) does not work