Function Comment() overwrites Comments written before

 

Hi,

I didn't find anything about that in the forum staff:

I want to write some Text on the Terminal Window. Very easy with the Comment () function. But the text should only appear if an appropriate extern variable of type bool is set. Problem is that every new call of the Comment () function overwrites the text written before. Any solutions (\n does not seems to work in the comment () function for that sense)?

Regards

Markus

Here is the code:

/|--------------------------------- Print Comments in Chart

if(Comments)
{
Comment("\n" +EAName, " is a Copyright © 2009 of ..",
"\nSignalBUY, SignalSELL, = " +SignalBUY,", " +SignalSELL,
"\nT o t a l O r d e r s = " + DoubleToStr(OrdersHistoryTotal(),2),"E q u i t y = " + DoubleToStr(AccountEquity(),2),"\n");
if (PrintingOrder)
Comment("TakeProfit, StopLoss, AutoStopLoss, SL = " + TakeProfit,", " +StopLoss,", " +AutoStopLoss,"\n");
if (PrintingRiskMM)
Comment( "SignalRest20P, RiskPercent, Lots = " + SignalRest20P,", " +RiskPercent,", " + DoubleToStr(Lots,2),"\n") ;
if (PrintingReverse)
Comment("\nSignalBUY, SignalReverseBUY,SignalReverseSELL = " +SignalReverseBUY,", " +SignalReverseSELL,"\n");
}

 
Daytraders:

Hi,

I didn't find anything about that in the forum staff:

I want to write some Text on the Terminal Window. Very easy with the Comment () function. But the text should only appear if an appropriate extern variable of type bool is set. Problem is that every new call of the Comment () function overwrites the text written before. Any solutions (\n does not seems to work in the comment () function for that sense)?

Regards

Markus

Here is the code:

/|--------------------------------- Print Comments in Chart

if(Comments)
{
Comment("\n" +EAName, " is a Copyright © 2009 of ..",
"\nSignalBUY, SignalSELL, = " +SignalBUY,", " +SignalSELL,
"\nT o t a l O r d e r s = " + DoubleToStr(OrdersHistoryTotal(),2),"E q u i t y = " + DoubleToStr(AccountEquity(),2),"\n");
if (PrintingOrder)
Comment("TakeProfit, StopLoss, AutoStopLoss, SL = " + TakeProfit,", " +StopLoss,", " +AutoStopLoss,"\n");
if (PrintingRiskMM)
Comment( "SignalRest20P, RiskPercent, Lots = " + SignalRest20P,", " +RiskPercent,", " + DoubleToStr(Lots,2),"\n") ;
if (PrintingReverse)
Comment("\nSignalBUY, SignalReverseBUY,SignalReverseSELL = " +SignalReverseBUY,", " +SignalReverseSELL,"\n");
}

I would say two possibilities:

  1. remember comment text in any variable and use Comment() func only to refresh, if changed or hide if should be hidden.
  2. Use the function ObjectCreate to create OBJ_TEXT or OBJ_LABEL - I have no experience with these two object types so you have to study Help or check some EA's here, which use that for nice boxes with text or any other objects
 
navodar:

I would say two possibilities:

  1. remember comment text in any variable and use Comment() func only to refresh, if changed or hide if should be hidden.
  2. Use the function ObjectCreate to create OBJ_TEXT or OBJ_LABEL - I have no experience with these two object types so you have to study Help or check some EA's here, which use that for nice boxes with text or any other objects


By the sounds of it option 1 is more suitable for the sort of simple logging which Daytraders is after, and personally I'd wrap it in a function such as the following which you then use instead of Comment(). However, this does require you to concatenate a single string to pass to the function, rather than catering for multiple parameters making up the combined text to display.


void XComment(string Text, bool ResetText = false)
{
   static string ExistingComment = "";
   if (ResetText) ExistingComment = "";
   ExistingComment = ExistingComment + Text;
   Comment(ExistingComment);
}

I.e. if you omit the optional second parameter, new text gets appended to whatever has already been displayed. To clear the existing comments and start with new text, pass true as an explicit second parameter to the function.

 

And something from the TIPs window: FREE CODE: Scrolling Comments

nice one too :-)

 

Hi jjc and navodar, thanx for quick answer. As I thouhgt: No easy solution. Maybe I'll skipp the conditional comment and write everything on the termial screen and wait for improvements in MetaTrader5. ;-)

wbr

Markus

 

You can make use of text labels of graphical objects in MT4.

In init(), you create the text labels in your desired format and position.

In the main loop, you can update the texts in the labels when ticks come in.

 
Comment("OrdersTotal = " + DoubleToStr(OrdersTotal(),0) + "\nLotPipValue = " + DoubleToStr(LotPipValue,2) + " Lot2PipValue = " + DoubleToStr(Lot2PipValue,2) + "\nLongProfit = " + DoubleToStr(LongProfit,2) + " LongLots = " + DoubleToStr(LongLots,2) + "\nShortProfit = " + DoubleToStr(ShortProfit,2) + " ShortLots = " + DoubleToStr(ShortLots,2));

Just thought I would update. As of MT4 built 432 it works.

Result:

OrdersTotal = 0

LotPipValue = 0.00 Lot2PipValue = 0.00

LongProfit = 0.00 LongLots = 0.00

ShortProfit = 0.00 ShortLots = 0.00

 
Dadas:

Just thought I woild update. As of MT4 built 432 it works.

What works ? \n for newline ? that has worked for a long time . . .
 
RaptorUK:
What works ? \n for newline ? that has worked for a long time . . .


Sure it works. The idea is to write just one comment line, preferably at the end of the code, and organize all the needed data to be viewed on the chart in such a way, that you see what you want, even if the line overwrites on every tick. You can always use if( someconditon ) { comment1; ) and so on... Or just use conditions for a certain text to show...

Wouldn't that solve the problem of Daytraders ?

 
Dadas:

Wouldn't that solve the problem of Daytraders ?

I think I prefer my solution . . .

https://www.mql5.com/en/forum/138327

 
RaptorUK:

I think I prefer my solution . . .

https://www.mql5.com/en/forum/138327


OK, I agree, if you are a more advanced coder.

I am not so advanced, so I try to find simpler solutions.

Many people looking for answers here are probably the less advanced coders.

Still, a Label is not a Comment and a Comment is not a Label.

Reason: