Needs some helt with the Comment() function

 

Hello,

I have a timer function that works fine  but I want a comment in the upper corner of the chart that says someting like this when the EA runs:

"Trade allowed between xx and xx"

I've tried to add the Comment() function but I cant place it right without errors..

      //Timer
      if(UseTimer == true)               
      {      
      if((Hour() >= OpenHour && Minute() >= OpenMinute && (Hour() < EndHour && Minute()<= EndMinute)))
      
      {
      bool TradeAllowed = true;
      }
      else TradeAllowed = false;
        }
      else TradeAllowed = true;   
 
kenned45900:

Hello,

I have a timer function that works fine  but I want a comment in the upper corner of the chart that says someting like this when the EA runs:

"Trade allowed between xx and xx"

I've tried to add the Comment() function but I cant place it right without errors..

You don't show a Comment() function in the code you have posted . . .  show what you tried.
 
      //Timer
      if(UseTimer == true)
      
      Comment("Timerfunction on");
                     
      {      
      if((Hour() >= OpenHour && Minute() >= OpenMinute && (Hour() <= EndHour && Minute()<= EndMinute)))
      
            {
      bool TradeAllowed = true;
      }
      else TradeAllowed = false;
        }
      else TradeAllowed = true;  
For example like this just to keep it simple. I'm not shure where to put the comment or where to put the semicolon or braces correct.
 
kenned45900:
For example like this just to keep it simple. I'm not shure where to put the comment or where to put the semicolon or braces correct.

Well maybe you should learn ?  Book

 //Timer
      if(UseTimer == true)
         {      
         Comment("Timerfunction on");
         if((Hour() >= OpenHour && Minute() >= OpenMinute && (Hour() <= EndHour && Minute()<= EndMinute)))
            {
            bool TradeAllowed = true;
            }
         else TradeAllowed = false;
         }
      else TradeAllowed = true;  
 
  1. Just to be clear
    Your Code
     RaptorUK's Code
    //Timer
    if(UseTimer == true)
    Comment("Timerfunction on");
    {      
    
    //Timer
    if(UseTimer == true)
       {      
       Comment("Timerfunction on");
    

  2. I'm not shure where to put the comment or where to put the semicolon or braces correct.
    learn to code
 

ok, thanks. I'm learning and have started reading the articles from forex-tsd.com. Just one more thing: If I use the Comment function more than one time it only shows the last comment. After I added the timerfunction comment my comment over disappeared. Is there a way I can make them all show in the chart?

     
     if(comment){Comment(
                       "Daglig 8 Ema="+EMA8+
                       "\nDaglig 21 Ema="+EMA21+
                       "\nDaglig 50 Ema="+EMA50+
                       "\nDaglig 100 Ema="+EMA100+
                       "\nDaglig 200 Ema="+EMA200+                       
                       "\nDaglig ATR ="+ATR+
                       "\nDaglig Rsi ="+Rsi+
                       "\nDailyHigh ="+DailyHigh+
                       "\nDailyLow ="+DailyLow+ 
                       "\nDailyRange ="+DailyRange+
                       "\nTotalOrders ="+TotalOrders+                       
                       "\nWeekDay ="+WeekDay+                                           
                       "\nYearDay ="+YearDay);}            
      //Timer
      if(UseTimer == true)            
                     
      {Comment("\nTimerfunction on");
            
      if((Hour() >= OpenHour && Minute() >= OpenMinute && (Hour() <= EndHour && Minute()<= EndMinute)))
      
      {
      bool TradeAllowed = true;
      }
      else TradeAllowed = false;
      }
      else TradeAllowed = true;    
 
kenned45900:

ok, thanks. I'm learning and have started reading the articles from forex-tsd.com. Just one more thing: If I use the Comment function more than one time it only shows the last comment. After I added the timerfunction comment my comment over disappeared. Is there a way I can make them all show in the chart?

You could save the first comment text in a string and then add the 2nd text to the string and then use the string in a Comment() function,  try it.
 
int start()
  {
//....................
//----
   if (ShowComment) subPrintDetails();    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//----------------------- PRINT COMMENT FUNCTION
void subPrintDetails()
{
   string sComment   = "";
   string sp         = "----------------------------------------\n";
   string NL         = "\n";

      sComment = "Server Time:        " + TimeToStr(TimeCurrent(), TIME_SECONDS) + NL;
      sComment = sComment +  NL;
      sComment = sComment +  "Daglig 8 Ema=  " + EMA8 + NL;
      sComment = sComment +  "Daglig 21 Ema=  " + EMA21 + NL;
      sComment = sComment +  "Daglig 50 Ema=  " + EMA50 + NL;
      sComment = sComment +  "Daglig 100 Ema=  " + EMA100 + NL;
      sComment = sComment +  "Daglig 200 Ema=  " + EMA200 + NL;                       
      sComment = sComment +  "Daglig ATR =  " + ATR + NL;
      sComment = sComment +  "Daglig Rsi =  " + Rsi + NL;
      sComment = sComment +  "DailyHigh =  " + DailyHigh + NL;
      sComment = sComment +  "DailyLow =  " + DailyLow + NL; 
      sComment = sComment +  "DailyRange =  " + DailyRange + NL;
      sComment = sComment +  "TotalOrders =  " + TotalOrders + NL;                       
      sComment = sComment +  "WeekDay =  " + WeekDay + NL;                                           
      sComment = sComment +  "YearDay =  " + YearDay + NL;            
      //Timer
      if(UseTimer == true)
         {            
          sComment = sComment + sp;               
          sComment = sComment + "Timerfunction on";
         } 



   Comment(sComment);
}
//+------------------------------------------------------------------+

maybe this way for example

make also in beginning line double  EMA8,EMA21,....;  int TotalOrders,....;  (not declare it after start)

for backtesting it is not needed to print comment set showcomment false if you like to backtest with more speed

 
kenned45900:

ok, thanks. I'm learning and have started reading the articles from forex-tsd.com. Just one more thing: If I use the Comment function more than one time it only shows the last comment. After I added the timerfunction comment my comment over disappeared. Is there a way I can make them all show in the chart?


Or you could use Objects . . .  https://www.mql5.com/en/forum/138327
 

Great!! Thank you both, I really appreciate your help. I have used the comment function and its great. I have also implemented som other useful information. It took me some time to make a fuction that calculates winners and loosers but I had to really try before asking for help again.

Now i will try the same using objects since its more flexible and fancy:-)

printscreen

Reason: