FREE CODE: Scrolling Comments

To add comments, please log in or register
DMS
108
DMS  
I've been writing quite a few EAs and I decided that I wanted to see the output of them in a "scrolling" fashion on the left side of the chart. So, I wrote this little function and I thought I'd share it. 

Basically, you call the function by sending a new comment string. That will be output at the very top of your chart and all of the previous comments will scroll down one "step" so that you can see the most current comment as well as a history of them.

You might also use this as a debug window since it works well for that too!

You'll need a couple of global variables like
Code:
//Determines how many of your previous comments are shown
extern int MaxCommentsToShow=25;
//An array to hold all of the comments
string allcomments[];
The main function is:
Code:
//+------------------------------------------------------------------+
//| Manage comments - Written by DMS                                           |
//+------------------------------------------------------------------+
void managecomments(string addcomment)
   {
   string tempcomments[];
   int commentscroll;
   string output;
   int CommentCount = ArrayRange(allcomments, 0);
   if(CommentCount<MaxCommentsToShow)
      {
      ArrayResize(tempcomments,CommentCount+1);
      ArrayCopy(tempcomments,allcomments,1,0,WHOLE_ARRAY);
      }
   else
      {
      ArrayResize(tempcomments,MaxCommentsToShow);
      ArrayCopy(tempcomments,allcomments,1,0,MaxCommentsToShow-1);
      }   
   tempcomments[0]=addcomment;
   CommentCount = ArrayRange(tempcomments, 0);
   ArrayResize(allcomments,CommentCount);
   ArrayCopy(allcomments,tempcomments,0,0,CommentCount);
   
   for(commentscroll=0;commentscroll<CommentCount;commentscroll++)
      {
      output = output + allcomments[commentscroll] +"\n";
      }    
   Comment(output);
   }
Finally, you call the function (and add a comment) with something like:
Code:
managecomments("show this on my chart!");
Ray
2646
Ray  

I like your idea.

Here's my implementation.

// Usage: 
// Comment(commentList(textString));// adds and outputs comment history with timestamps
// Comment(commentList());          // null text redisplays existing comment history
// function
 string commentList(string text = ""){
  static string list[31];                                       // list size == 30
  static int r = 0;                                             // r is the array element to return to the caller
  if(text == "") return(list[r]);                               // null text received, return the current comment string
  if(r<ArraySize(list)-1)r++;                                   // increment return pointer while list grows
  for(int i=r-1;i>0;i--){list[i]=list[i-1];}list[r]="";         // make room for new item, clear old concatenated string
  list[0]="\n "+TimeToStr(TimeLocal(),TIME_SECONDS)+"  "+text;  // insert new list item
  for(i=0;i<r;i++){list[r]=list[r]+list[i];}                    // recreate the concatenated string
  return(list[r]);                                              // return the concatenated string
 }

Panjianom Adi Pratomo
532
Panjianom Adi Pratomo  

I am sorry to bump this thread but it is very usefull!

Thanks DMS & Ray.

To add comments, please log in or register