Author: Copyright (c) 2010, Fai Software Corp.
nyoron

Overview of the Tool Logic

This script is designed as an on-screen information display for the MetaTrader platform. Rather than calculating complex market trends or providing trading signals, its primary purpose is to render a persistent, multi-line text block directly onto your trading chart. It acts as a customized dashboard for displaying static notes, instructions, or personal reminders.

Core Functionality

The logic operates through three main processes:

1. Text Processing and Formatting The script contains a predefined message block. The logic is structured to recognize line breaks within this text. It automatically separates the long message into individual lines so that they can be stacked vertically on your screen, ensuring the layout remains organized and readable rather than appearing as one continuous horizontal string.

2. Dynamic Positioning and Layout The script handles the "visual heavy lifting" of placing text on a chart:

  • Vertical Alignment: It calculates the vertical position of each line based on a user-defined font size and spacing, ensuring that each new line appears directly below the previous one without overlapping.
  • Horizontal Wrapping: To prevent text from running off the edge of the screen, the logic includes a "wrapping" feature. If a single line of text is too long to fit in one horizontal block, the script automatically splits it into multiple segments and places them side-by-side across the chart.

3. Memory Management To ensure the trading platform remains fast and stable, the script includes a cleanup routine. Every time the display updates, the logic identifies and removes old text objects before drawing new ones. This prevents "ghost" text from accumulating or slowing down your interface.

User Customization Options

The logic allows you to adjust several visual parameters to fit your specific screen resolution:

  • Font Details: You can change the font family, color, and size.
  • Positioning: You can set the "X" (horizontal) and "Y" (vertical) starting coordinates to move the entire block of text to any corner or area of your chart.
  • Spacing: You can adjust the gap between lines to improve readability depending on the font style chosen.
14 Views
0 Downloads
0 Favorites
nyoron
//+------------------------------------------------------------------+
//|                                                       nyoron.mq4 |
//|                           Copyright (c) 2010, Fai Software Corp. |
//|                                    http://d.hatena.ne.jp/fai_fx/ |
//+------------------------------------------------------------------+
#property copyright "Copyright (c) 2010, Fai Software Corp."
#property link      "http://d.hatena.ne.jp/fai_fx/"

#property indicator_chart_window
// http://useyan.x0.com/s/html/mono-font.htm “™•ƒtƒHƒ“ƒg‚Ì—á
extern string FontName = "‚l‚r ‚oƒSƒVƒbƒN";  //"‚l‚r ƒSƒVƒbƒN"@"‚l‚r –¾’©" "HGs‘‘Ì" "GungsuhChe"
extern color  FontColor = White; 
extern int    FontSize = 12;   
extern int    LineSpace = 4;//sŠÔ

extern int    XShift = 350;//ƒIƒuƒWƒFƒNƒgŒQ‚̍¶‘¤ƒXƒy[ƒX
extern int    YShift = 10;//ƒIƒuƒWƒFƒNƒgŒQ‚̏㑤ƒXƒy[ƒX

extern int    BlockShift = 0;// 60•¶Žš–ˆ‚̃uƒƒbƒN‚Ì”z’uƒYƒŒ’²®—p

// OS ‚É‚æ‚Á‚Ä60•¶ŽšƒuƒƒbƒN‚̃TƒCƒY‚ªˆá‚¤‚̂ŗv’ˆÓB
// ƒtƒHƒ“ƒgƒTƒCƒY 7`18 ‚ð‘z’èB

// for Vista
//int BlockSize[] = {0,1,2,3,4,5,6,360,420,480,480,540,600,660,720,780,780,840,900};

// for WindowsXP
int BlockSize[] = {0,1,2,3,4,5,6,300/*7*/,300,300,420/*10*/,420,480,540,540/*14*/,600,660,660,720/*18*/};

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if(FontSize > 18 ) FontSize = 18;
   if(FontSize <  7 ) FontSize =  7;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   DelObj();
   Comment("");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
string msg = 
"@@@@@@@@@@ @ -] 'LPPMR¤"+"\n"+
"@@ @ @ @ @ @ ^@^\" MR R@@_"+"\n"+
"@@@@@@@@@//, '/@@@@ RÊ @¤@R"+"\n"+
"@@@@@@@@ V {_{@@@ @@@Ø| ‚Œ.„  i| @‚É"+"\n"+
"@@@@@@@@ Ú!¬‚Œƒm@@@ MR ˜¸@|Ai|@@‚å"+"\n"+
"@@@@@@@ @ R|l@œ@@@œ@ |@.|Ʉ @ ‚ë"+"\n"+
"@ @ @ @@@@@ |́½ ¤_,¤_,¼½j @|@, |.@@l"+"\n"+
"@@@@@@@@@@|@/Ül,¤ __,@ƒCƒ@ƒg |/ |@ ‚ñ"+"\n"+
".@@@@@@@@@ | /@ /::|ŽO/::/^@ R |"+"\n"+
"@@@@@@@@@ | |@@l SÉ:::/ ƒq::::œc, |";

CommentOBJ(msg);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// ‰üs‚Å‹æØ‚Á‚ďˆ—‚·‚éB
string CommentOBJ(string msg){
   DelObj();
   int start = 0;
   int i = 0;
   msg = msg + "\n";
   string msg_unit;
   while(i<500){  // 500sˆÈ‰º‚ð‘z’è
      int n = StringFind(msg,"\n",start);
      if(n!=-1){
         if(n-start > 0){
            msg_unit = StringSubstr(msg,start, n-start);
         }else{
            msg_unit =" ";
         }
         start = n+1;
         //Print(start," ",n," ",msg_unit);
         DrawTXTLine("TXT-"+i,msg_unit,XShift,YShift+i*FontSize+i*LineSpace);
      }else{
         break;
      }
      i++;
   }
}
//+------------------------------------------------------------------+
// TXT- ‚ÅŽn‚Ü‚éƒIƒuƒWƒFƒNƒg‚ð‘Síœ‚·‚é
void DelObj(){
   string objname;
   for(int i=ObjectsTotal();i>=0;i--){
      objname = ObjectName(i);
      if( StringFind(objname,"TXT-")>=0) ObjectDelete(objname);
   }
}
//+------------------------------------------------------------------+
// 60•¶Žš–ˆ‚É‹æØ‚Á‚ă‰ƒxƒ‹ƒIƒuƒWƒFƒNƒg‚ðì¬‚·‚éB
void DrawTXTLine(string objname, string msg, int X, int Y)   
{   
   int len = StringLen(msg);
   for(int i=0;i*60<len;i++){
      string submsg = StringSubstr(msg,60*i,60);
      ObjectCreate(objname+i,OBJ_LABEL,0,0,0);   
      ObjectSet(objname+i,OBJPROP_XDISTANCE, X+(BlockSize[FontSize]+BlockShift)*i);   
      ObjectSet(objname+i,OBJPROP_YDISTANCE, Y);  
      ObjectSetText(objname+i,submsg,FontSize,FontName,FontColor);   
   }
}  
//+------------------------------------------------------------------+

Comments