if (OrderType()==OP_BUY && OrderComment()[b]=[/b]"LONG")
That is one of reasons at least.
The second is that the comment is not guaranteed to be preserved over the orders life (and death). The server has a right to change or amend it completely.
Just don't rely on the comment and leave the first condition only:
if (OrderType()==OP_BUY)
Nobody can change the type of market order.
if (OrderType()==OP_BUY && OrderComment()[b]=[b]"LONG")
That is one of reasons at least.
The second is that the comment is not guaranteed to be preserved over the orders life (and death). The server has a right to change or amend it completely.
Just don't rely on the comment and leave the first condition only:
if (OrderType()==OP_BUY)
Nobody can change the type of market order.
Thx for quick reply Irtron :)
Yes i'm sorry i wrote wrong code correct one in my EA is with == , so is not a syntax problem. But as you said is a comment problem since as far I understand there is no way to retrieve it in history when an order is closed.
Is there any other way to retrieve a particular order already closed in history ?
Ops I was wrong , I changed my first post ;)
Why not? The original comment might be still there. Although it's likely to be changed by the server, e.g. if the position is closed by the server when stoploss or takeprofit triggers.
This is much more reliable way than the comment parsing.
This is much more reliable way than the comment parsing.
Mmm magicnumber is unique within the same EA and my problem is that I have to indentify two different kind of buy/sell , called BUY1,SELL1,BUY2,SELL2 because i have to handle them in different way, this is why i tried to find some unique information in history and magicnumber I think isn't usefull for this purpouse :(
#define BUY1FLAG 0x00010000 #define BUY2FLAG 0x00020000 #define SELL1FLAG 0x00040000 #define SELL2FLAG 0x00080000 #define EA_ID_MASK 0x0000ffff int EaId = 1234; // < 0x0000ffff (= 65535) int start() { int mn = 0; switch (op) { case buy1: mn = BUY1FLAG; break; case buy2: mn = BUY2FLAG; break; case sell1: mn = SELL1FLAG; break; case sell2: mn = SELL2FLAG; break; } mn += EaId; OrderSend(..., mn, ...); // ... mn = OrderMagicNumber(); if ((mn & EA_ID_MASK) == EaId) { if ((mn & BUY1FLAG) != 0) Print("buy1"); else if ((mn & BUY2FLAG) != 0) Print("buy2"); else if ((mn & SELL1FLAG) != 0) Print("sell1"); else if ((mn & SELL2FLAG) != 0) Print("sell2"); else Print("You\'re not my type"); } else Print("You\'re not mine whatsoever"); return (0); }
Things like this are better discussed on programmer's forum https://www.mql5.com/forum/en
Thanks a lot Irtron this code will be really usefull for my EA ;)
You're welcome.
mqlexpert [at] gmail [dot] com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
is there a way using HistoryTotal function to be able to find a particular order (buy or sell) closed ?
I tried with this code but it seems not working :
And when a buy order was in place using OrderSelect I identified this using "LONG" as comment (and "SHORT" if a sell order) :
Maybe is not supported OrderComment using MODE_HISTORY mode? And if so how can I solve this issue?
thx a lot ;)
Skyline