MQL4 - automated forex trading   /  

Forum

Function Comment() overwrites Comments written before

Back to topics list To post a new topic, please log in or register

avatar
3
Daytraders 2009.08.21 13:49 

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");
}

Indicator Alternative Ichimoku – Setup, Examples of Usage

Indicator Alternative Ichimoku – Setup, Examples of Usage

How to set up Alternative Ichimoku correctly? Read the description of parameters setting up. The article will help you understand the methods of setting up parameters not only of the indicator Ichimoku. Certainly you will also better understand how to set up the standard Ichimoku Kinko Hyo.


avatar
411
navodar 2009.08.21 14:36 
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

avatar
1138
jjc 2009.08.21 15:03 
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.



avatar
411
navodar 2009.08.21 15:56 

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

nice one too :-)


avatar
3
Daytraders 2009.08.21 18:14 

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


avatar
13
ppc123 2009.08.26 08:03 

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.

Back to topics list  

To add comments, please log in or register