help printing comments on chart

 

Hi,

I am learning by taking parts of old EA's I have had programmed and piecing them together in new EA's.  

 

I have an EA that uses an account number and expiry date for validation. The code below works fine and the EA runs perfectly.

 

bool working;                                           
input int accountNumber = 348888; 
input datetime expirationDate = D'2016.12.30'; 
bool RemoveExpert = true;                            

int init()
{
   return(0);
}

int start()
{
  
   if(!goodAccountNumber() || RemainingDays()<0)    
     {
     working = false;
      
      if(RemoveExpert)
        {
         ExpertRemove();
        }
      return (0);            
     }                        
   }
   
bool goodAccountNumber(){              
bool signal = false;
if(AccountNumber()==accountNumber)
  {
   signal = true;
  }
return(signal);
}
int RemainingDays(){
int remain = -1;
if(expirationDate>TimeCurrent())
  {
   datetime date =  expirationDate - TimeCurrent();
   remain = ((int)date)/60/60/24;
  }
else
  {
   remain = -1;
  }
return(remain);
}  

 

 I am now trying to print comments relating to the account number and expiry date as shown in the next piece of code below.

The EA compiles without errors but when I try run the EA after adding this second bit of code, it will not take. i.e. the EA doesn't start at all.

  

bool working;                                           


input int accountNumber = 348888;
input datetime expirationDate = D'2016.12.30'; 
bool RemoveExpert = true;                             


int init()

{
   return(0);
}
int start()
   
     {

   if(!goodAccountNumber() || RemainingDays()<0)
     
     working = false;
      DoComment();            //////////////////////////////////////I added this line and defined it below
      if(RemoveExpert)
        {
         ExpertRemove();
        }
      return (0) ;
     }
     
   
bool goodAccountNumber(){              
bool signal = false;
if(AccountNumber()==accountNumber)
  {
   signal = true;
  }
return(signal);
}
int RemainingDays(){
int remain = -1;
if(expirationDate>TimeCurrent())
  {
   datetime date =  expirationDate - TimeCurrent();
   remain = ((int)date)/60/60/24;
  }
else
  {
   remain = -1;
  }
return(remain);
}  

//////////////////////////////////////////////////////////////Defining DoComment

void DoComment()
{
   string amr = "";
   amr += "\n\n";
   amr+= "Copyright c 2014 Brian";
   amr += "\n\n";
   if(!goodAccountNumber())
     {
      amr+= "Invalid Account Number!";
      amr += "\n\n";
     }
   if(RemainingDays()>=0)
     {
      amr+= "EA Expire on date: " + TimeToStr(expirationDate,TIME_DATE) + " Remaining Days: " + DoubleToStr(RemainingDays(),0);
     }
   else
     {
      amr+= "EA Expired!";
     }
     }
     
/////////////////////////////////////////////////////////////

 

 I apologise for such a long piece of code but would appreciate any help.

 Thanks.

Regards, 

Brian 

 

You have two options:

  1. Comment() which will disappear if the chart is closed or overwritten by another Comment() Comment(amr);
  2. Place a TextLabel (=Object) in one of the 4 corners, which can be deleted via the chart's Object-List.
 

Hi Calli,

Thanks for your message.

Sorry, a bit of a beginner here. Can you perhaps elaborate?

Are you saying in (1) above that if there is more than one Comment() in the code then it can interfere with the other?

There are other Comment()'s which I can show you if that will help.

Thanks,

Brian 

 

Does your code actually call the Comment() function? I do not see it on the code you posted.

Comments work with newline characters.

 
Enrico Lambino:

Does your code actually call the Comment() function? I do not see it on the code you posted.

Comments work with newline characters.

Hi Enrico.

Thanks for your message.

Can you perhaps give me an example of how to call a Comment() function using my code above.

 Do I need to put something in the brackets on this line? 

DoComment();            //////////////////////////////////////I added this line and defined it below

 

Thanks again,

 
Brian:

Hi Enrico.

Thanks for your message.

Can you perhaps give me an example of how to call a Comment() function using my code above.

 Do I need to put something in the brackets on this line? 

 

Thanks again,

Hi Enrico,

I think I figured it out.

Comment(amr);

 Will let you know if I have more questions. Thanks for your help.

Brian 

 

Oh no.

The comment is working but the EA is still not loading?

 Let me play around a bit and see what I can figure out:)

 

Regards,

Brian 

 
Brian:

Oh no.

The comment is working but the EA is still not loading?

 Let me play around a bit and see what I can figure out:)

 

Regards,

Brian 

Not sure exactly about that problem, but my guess is that:

RemoveExpert = true

removes the EA from the chart when some conditions are not met. You saw the comments, so that means that EA processed at least one tick.

 
Enrico Lambino:

Not sure exactly about that problem, but my guess is that:

removes the EA from the chart when some conditions are not met. You saw the comments, so that means that EA processed at least one tick.

Thanks Enrico - I will look at that.

 Regards,

Brian 

 

you can use something like this to print stuff on the chart. 

void topPrint(string text,int x, int y, string suffix)
{
   ObjectCreate("O_"+suffix, OBJ_LABEL, 0, 0, 0);
   ObjectSetText("O_"+suffix,text, 12, "Verdana", clrPurple);
   ObjectSet("O_"+suffix, OBJPROP_CORNER, 0);
   ObjectSet("O_"+suffix, OBJPROP_XDISTANCE, x);
   ObjectSet("O_"+suffix, OBJPROP_YDISTANCE, y); 
}
topPrint("this purple message will be placed in the top left corner at 20px distance from the corner",20,20,"unique_name");
 
puiucristian:

you can use something like this to print stuff on the chart. 

Thanks Puiucristian