Using closed order Comment for EA algorithm

 
Can i use  closed order comment to work my EA trading decision or it is allowed in MT4?
for(int i= OrderHistoryTotal()-1; i>=0; i--)
{
    if(OrderSelect(i,SELECT_BY_POSITION,MODE_HISTORY))

   if(OrderSymbol()==Symbol() && OrderMagicNumber()== Magicnumber)
 {
      if(StringSubstr(OrderComment(),StringLen(OrderComment())-4,4)=="[sl]") //the last 4 text of the closed order comment
   {
 
       to do here........... l
    }
  }
}
 
Gbenga Ayodele:
Can i use  closed order comment to work my EA trading decision or it is allowed in MT4?
In general, using the order comment to identify trades is not good. Indeed, the broker can change the order comment and that value is not fixed.

I suggest you only use magic numbers to do such identification. On MQL4, you can choose the magic number at trade opening. And on MQL5, you can create multiples CTrade instances and set a different magic number for each of those.

 

Some brokers modify comments with “[sl]”, others do not. Do not depend.

Not a good idea to use comments, brokers can change comments, including complete replacement.

 
William Roeder #:

Some brokers modify comments with “[sl]”, others do not. Do not depend.

Not a good idea to use comments, brokers can change comments, including complete replacement.

Thanks a lot. I really appreciate....

It is because of these brokers modification  that is making me wonder if it is possible to use comments.

I want to separate orders closed by StopLoss from  orders closed by Opposite signal as part of conditions for opening next trade.

i don't know if there is another way to do this.

 

Please don't post randomly in any section. Your question is not related to the section you posted.

MT4/mql4 has it's own section on the forum.

This thread has been moved to the correct section, so please don't create another topic.

 
Gbenga Ayodele #: I want to separate orders closed by StopLoss from  orders closed by Opposite signal as part of conditions for opening next trade.

Why do you care after the fact?
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem
          The XY Problem

 
Gbenga Ayodele #:

Thanks a lot. I really appreciate....

It is because of these brokers modification  that is making me wonder if it is possible to use comments.

I want to separate orders closed by StopLoss from  orders closed by Opposite signal as part of conditions for opening next trade.

i don't know if there is another way to do this.

Use virtual stops …
This way you can flag the virtual stop loss . 
I mean use also virtual stops … which should be triggered before orders stoploss … or… when you check for closed orders, you identify the ones closed on reversed signal, and the rest should be closed on SL…