Print info with OrderComment() function?

 

Hello,

how to print more than one variable to order comment with OrderComment() function?

Example:

//+------------------------------------------------------------------+
//|  It calculates the data for opening a new order                  |
//+------------------------------------------------------------------+
void CalculateNewMarketValues(int    trSignal,
                              int    & marketType,
                              double & marketLots, 
                              double & marketSL,
                              double & marketTP,
                              string & marketcomment
                              )
   {
   // if there is no trade signal, exit
   //Print("CalculateNewMarketValues()  trSignal=",trSignal);
   if (trSignal==OP_BALANCE) return;
 
   marketType    =-1; // this means that we won't open
   marketLots    = 0;
   marketSL      = 0;
   marketTP      = 0;
   marketcomment = "";
 
 
//----
   //  insert your own code to calculate all parameters

marketcomment =double1, doubl2...
//---- return; }

 
MINTA:

Hello,

how to print more than one variable to order comment with OrderComment() function?

Example:

OrderComment() returns the string stored as a comment with the order . . . order comments are not reliable, they can be changed or replaced by your Broker.

To send 2 values within OrderSend as the order comment you could use StringConcatenate()

marketcomment = StringConcatenate(double1,"", double2);
 
RaptorUK:

OrderComment() returns the string stored as a comment with the order . . . order comments are not reliable, they can be changed or replaced by your Broker.

To send 2 values within OrderSend as the order comment you could use StringConcatenate()

I think you meant to include a space between your quotation marks in the StringConcatenate() function. (If you don't do that the numbers all run together.)

As a script to test this ...

int start(){
   Comment( StringConcatenate(Ask," ",Bid) );
   
   return(0);
}

using Ask and Bid as convenient doubles.

 

Personally I would use something with a bit more formatting ...

int start(){
   Comment( DoubleToStr(Ask,Digits)+ " : " + DoubleToStr(Bid,Digits) );
   
   return(0);
}

since the earlier version only gives 4 digits after the decimal point.

In the real code it would be ...

   string marketComment = DoubleToStr(Ask,Digits)+ " : " + DoubleToStr(Bid,Digits);

for example.

 
The string in OrderComment is retained entirely if the order has not been partially or fully closed.
 
Thanks.
 
sxTed:
The string in OrderComment is retained entirely if the order has not been partially or fully closed.
Wrong, brokers can change comments, including complete replacement.Your broker may not be changing it currently, but that may change. Your code can not assume it will never happen.
 
dabbler:

I think you meant to include a space between your quotation marks in the StringConcatenate() function. (If you don't do that the numbers all run together.)

Yup, you are correct, it was a typo :-)
 
WHRoeder:
Wrong, brokers can change comments, including complete replacement.Your broker may not be changing it currently, but that may change. Your code can not assume it will never happen.
Brokers only change the OrderComment string after the order has been partially or fully closed. After the order has been closed fully, some brokers add a prefix denoting a profit or loss. If the order is partially closed, the string in OrderComment is lost but OrderMagicNumber is retained.
 
sxTed:
Brokers only change the OrderComment string after the order has been partially or fully closed. After the order has been closed fully, some brokers add a prefix denoting a profit or loss. If the order is partially closed, the string in OrderComment is lost but OrderMagicNumber is retained.

And your documentation for that statement is where? Where in the documentation does it say the brokers can change the comment at all? Yet they do.

In the link I provided 1005phillip said "Oanda for example completely overwrites the user's stated comment for the trade" He did not say AFTER the trade closes.

Assume the comment isn't modified while open and watch your EA break sometime in the future when you move to a different broker, or the current broker changes something. It's your money.

 
WHRoeder:

And your documentation for that statement is where? Where in the documentation does it say the brokers can change the comment at all? Yet they do.

In the link I provided 1005phillip said "Oanda for example completely overwrites the user's stated comment for the trade" He did not say AFTER the trade closes.

Assume the comment isn't modified while open and watch your EA break sometime in the future when you move to a different broker, or the current broker changes something. It's your money.

And your documentation for that statement is where? - From using MT4 with various brokers.

In the link I provided 1005phillip said "Oanda for example completely overwrites the user's stated comment for the trade" He did not say AFTER the trade closes. - 1005phillip DID SAY AFTER THE TRADE CLOSES "Many other brokers will append a notation to the end of the order comment (overwriting pre-existing characters in the ordercomment if the space is needed) to indicate if the order was closed by virtue of triggering the defined stoploss or takeprofit values."

Assume the comment isn't modified while open and watch your EA break sometime in the future when you move to a different broker, or the current broker changes something. It's your money. Thank you for your concern and we must be vigilant and trust that the OrderMagicNumber is not also modified while the order is open!

Reason: