How to code to get the symbol name in the trade position comments?

 
How to code to get the symbol name in the trade position comments?
 
Sathish Justin: How to code to get the symbol name in the trade position comments?

Why? The symbol is already part of a position's properties which you can query with ease, both in code or visually on the trade details or in the trade history?

 
Fernando Carreiro #:

Why? The symbol is already part of a position's properties which you can query with ease, both in code or visually on the trade details or in the trade history?

For each trade, i want the symbol name and period along with a code to be appeared in the comments, to identify which EA executed the trade.  I tried as below, but giving error


StringFormat("AR - ",string _Symbol(),string _Period())

 
Sathish Justin #:

For each trade, i want the symbol name and period along with a code to be appeared in the comments, to identify which EA executed the trade.  I tried as below, but giving error


StringFormat("AR - ",string _Symbol(),string _Period())

Try this:

   string commStr = StringFormat("AR - %s %s", _Symbol, EnumToString(_Period) );


 
Sathish Justin #:

For each trade, i want the symbol name and period along with a code to be appeared in the comments, to identify which EA executed the trade.  I tried as below, but giving error


StringFormat("AR - ",string _Symbol(),string _Period())

Probably you won't happy with this idea as the trade server will change the comment of a position e.g. by entering the way it way closed (sl or tp).

Use the magic number for this. It is your ID of a position (all positions by an EA).

 
R4tna C #:

Try this:

   string commStr = StringFormat("AR - %s %s", _Symbol, EnumToString(_Period) );


Hey Ratna,

Thank you so much.  The output is coming like this "AR - EURUSD PERIOD_H1", Is it possible to remove the period from this to have like this "AR - EURUSD - H1"

 
R4tna C #:

Try this:

   string commStr = StringFormat("AR - %s %s", _Symbol, EnumToString(_Period) );


Is there a way to add EA Name along with this, if so please how?

 
Carl Schreiber #:

Probably you won't happy with this idea as the trade server will change the comment of a position e.g. by entering the way it way closed (sl or tp).

Use the magic number for this. It is your ID of a position (all positions by an EA).

Hi Carl,

Thanks for your suggesstion, the EA is already having the magic number, but it is Random Number, so difficult to track that.  So, I am trying to add this.  Once the positions are closed, i don't have any requirement to refer this.  This i need to refer during the open positions and many trades happen parallelly from different charts at different timeframes

 
Sathish Justin #: Thanks for your suggesstion, the EA is already having the magic number, but it is Random Number, so difficult to track that.  So, I am trying to add this.  Once the positions are closed, i don't have any requirement to refer this.  This i need to refer during the open positions and many trades happen parallelly from different charts at different timeframes

Then don't use a random magic number. Make a magic number that is based off constant data.

For example, a hash of the symbol name, a compact encoding of the time-frame, and an EA ID.

Using the comment is not a good idea as the brokers will change or even delete it, especially when the stop-loss or take-profit is hit. It will also change if you have partial closing.

So, in essence, don't use the order comments.

 
Fernando Carreiro #:

Then don't use a random magic number. Make a magic number that is based off constant data.

For example, a hash of the symbol name, a compact encoding of the time-frame, and an EA ID.

Using the comment is not a good idea as the brokers will change or even delete it, especially when the stop-loss or take-profit is hit. It will also change if you have partial closing.

So, in essence, don't use the order comments.

Hi,

Thanks, whether the magic number can be a string.

 
Sathish Justin #:

Is there a way to add EA Name along with this, if so please how?

This may help:

  string commStr = StringFormat("AR - %s %s", _Symbol, EnumToString(_Period) ) + "-" +__FILE__;
   StringReplace(commStr, "PERIOD_", "");
   StringReplace(commStr, ".mq5", "");
 
Reason: