Download MetaTrader 5

Multiple Lines using Comment()

To add comments, please log in or register
Adrian Suarez
36
Adrian Suarez  

Hello all,

I am wondering if there is a way to get multiple lines of text using Comment(). I have tried to search, but no luck so far.

Thanks in advance,

LW

minhae
47
minhae  

EX)

bjectCreate("Line1",OBJ_HLINE,0,0,1.37240);

bjectCreate("Line2",OBJ_HLINE,0,0, );

bjectCreate("Line3",OBJ_HLINE,0,0, );

bjectCreate("Line4",OBJ_HLINE,0,0, );

ok?

dabbler
1103
dabbler  
LeagueORobots:

Hello all,

I am wondering if there is a way to get multiple lines of text using Comment(). I have tried to search, but no luck so far.

Thanks in advance,

LW

You just need to include a newline character in your text string. The newline is "\n" as a string so you might say

Comment("Hello\nWorld");
Dan
220
Dan  
LeagueORobots:

Hello all,

I am wondering if there is a way to get multiple lines of text using Comment(). I have tried to search, but no luck so far.

Thanks in advance,

LW


#define NL                 "\n"         // <--- add this at the top of your ea or subsitute \n for NL on all the lines

    
Comment("MagicNumber1 = " + MagicNumber1 + NL +            
        "MagicNumber2 = " + MagicNumber2 + NL +
        ".................................................................." + NL +
        "Total Number of Main Trades = " + MainTrade + NL + 
        "Total Number of Main Trades Profit = " + MWin + NL +
        "Total Number of Main Trades Loss = " +   MLoss + NL +
        ".................................................................." + NL +
        "Total Number of Sub Trades = " +  SubTrade + NL +
        "Total Number of Sub Profit = " +  SWin + NL +
        "Total Number of Sub Loss = " +    SLoss + NL +
        "......................................................................................................" + NL +
        "Sub Trades Win % (Sub Trade win vs total Sub Trades) = "+ (SWin*100)/SubTrade+"%"+ NL +
        "Main Trade win % (Main wins vs total Main Trade) =  "+ (MWin*100)/(MainTrade)+"%"+ NL +
        "Sub Trades % to Main Trades (Total Sub Trades vs Main Trades) = "+ (SubTrade*100)/(MainTrade)+"%"+ NL +
        "......................................................................................................");
whroeder1
14786
whroeder1  
string line1 = "this is line one",
       line2 = "below that is line two",
       line3 = "you get the idea";
Comment(line1+"\n",
        line2+"\n",
        line3+"\n");
whroeder1
14786
whroeder1  
Ha, 3 replies, in the same minute.
Simon Gniadkowski
Moderator
18004
Simon Gniadkowski  

Something I knocked up last week, I noticed Comment couldn't keep up in the Strategy Tester and was falling behind, in other words, it was slow in putting messages on screen and wasn't able to put the correct message on screen when I did an automatic Chart Grab . . . so I created this, it was a bit of a rush job but it did what I wanted.

void CommentLab(string CommentText)
   {
   string CommentLabel;
   int CommentIndex = 0;
   
   if (CommentText == "")
      {
      //  delete all Comment texts
      while(ObjectFind(StringConcatenate("CommentLabel", CommentIndex )) >= 0)
         {
         ObjectDelete(StringConcatenate("CommentLabel", CommentIndex ));
         CommentIndex++;
         }
      return;
      }
   
   while(ObjectFind(StringConcatenate("CommentLabel", CommentIndex )) >= 0)
      {
      CommentIndex++;
      }
      
   CommentLabel = StringConcatenate("CommentLabel", CommentIndex);  
   ObjectCreate(CommentLabel, OBJ_LABEL, 0, 0, 0 );
   ObjectSet(CommentLabel, OBJPROP_CORNER, 0);
   ObjectSet(CommentLabel, OBJPROP_XDISTANCE, 5);
   ObjectSet(CommentLabel, OBJPROP_YDISTANCE, 15 + (CommentIndex * 15) );
   ObjectSetText(CommentLabel, CommentText, 10, "Tahoma", Status_Color );   
   
   }
Adrian Suarez
36
Adrian Suarez  
Thank you all for the help.
To add comments, please log in or register