nyoron
Download scriptOverview 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.
//+------------------------------------------------------------------+
//| 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 tHgÌá
extern string FontName = "lr oSVbN"; //"lr SVbN"@"lr ¾©" "HGsÌ" "GungsuhChe"
extern color FontColor = White;
extern int FontSize = 12;
extern int LineSpace = 4;//sÔ
extern int XShift = 350;//IuWFNgQ̶¤Xy[X
extern int YShift = 10;//IuWFNgQÌã¤Xy[X
extern int BlockShift = 0;// 60¶ÌubNÌzuY²®p
// OS ÉæÁÄ60¶ubNÌTCYªá¤ÌÅvÓB
// tHgTCY 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 =
"@@@@@@@@@@ @ -] 'LPPMR¤"+"\n"+
"@@ @ @ @ @ @ ^@^\" MR R@@_"+"\n"+
"@@@@@@@@@//, '/@@@@ RÊ @¤@R"+"\n"+
"@@@@@@@@ V {_{@@@ @@@Ø| . i| @É"+"\n"+
"@@@@@@@@ Ú!¬m@@@ MR ¸@|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){ // 500sȺð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ÜéIuWFNgðSí·é
void DelObj(){
string objname;
for(int i=ObjectsTotal();i>=0;i--){
objname = ObjectName(i);
if( StringFind(objname,"TXT-")>=0) ObjectDelete(objname);
}
}
//+------------------------------------------------------------------+
// 60¶ÉæØÁÄxIuWFNgð쬷é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