Display optimized for text output of console type charts - MetaTrader 5 Library - MT4/MT5 Resources




The library contains two types of displays. The first one, label display , is based on CChartObjectLabel. The second one, CanvasDisplay, is based on CCanvas. The monitor is optimized for rendering frequency. In addition to the main Expert Advisor that demonstrates the work of Demo.mq5, there are two variants CanvasVsLabelsTester.mq5 dedicated to performing measurements on price movements in the tester. As well as the universal canvas and tags.mq5 , which performs measurements on testers and charts. These measurements can be compared with each other. For more details on comparing display speeds, see Link canvases vs. labels .
//+------------------------------------------------------------------+ //|ChartDisplayDemo.mq5 | //| Copyright 2021, © Cyberdev | //| https://www.mql5.com/en/users/cyberdev/seller | //+------------------------------------------------------------------+ #Property Copyright "Copyright 2021, © Cyberdev." #Property association "https://www.mql5.com/en/users/cyberdev/seller" # Property version "1.00" //+------------------------------------------------------------------+ //|| //+------------------------------------------------------------------+ #Include "cyberdev\ChartDisplay.mqh" //+------------------------------------------------------------------+ //|| //+------------------------------------------------------------------+ enum output type { ot canvas, // canvas ot tag // tag }; //+------------------------------------------------------------------+ //|| //+------------------------------------------------------------------+ Input OutType outType = otLabels; // outType - display type Input integer n lines = 50 ; // nLines - number of lines on the display input boolean optimizeupdate = false ; // optimizeUpdate - label optimization Input integer width = 406 ; // bWidth - display width Input integer lY_distance = 14 ; // lY_Dist - distance between lines input boolean back = false ; // back - the background of the label //+------------------------------------------------------------------+ //|| //+------------------------------------------------------------------+ String*display; CChart chart; //+----------------------------------------------------------------------------------+ //|Expert initialization function| //+------------------------------------------------------------------+ Integer initialization () { Chart.Append( ChartID ()); Chart.ShowGrid( wrong ); Chart.ColorBackground( C'194,231,197' ); Chart.ColorBarUp( clr Dodge Blue ); Chart.ColorBarDown( clrblue-purple ); Chart.ColorCandleBull( clr Dodge Blue ); Chart.ColorCandleBear( clrblue-purple ); Chart.ColorForeground( black ); transform (outputType){ case ot canvas: display = new canvas display(); rest ; case ot tags: display = new label display(); rest ; default : Return initialization failed ; } if ((outType == otLabels && return && ! dynamic conversion(Display).createExt(nLines, 10 , 10 , bWidth, lY_Dist)) || !display.create(nLines, 10 , 15 , bWidth, lY_Dist)) Return initialization failed ; Return ( initialization successful ); }>//+------------------------------------------------------------------+ //|Expert de-initialization function| //+------------------------------------------------------------------+ Blank solution initialization ( const integer reason) { Delete display if ( check pointer (display) == POINTER_DYNAMIC ); Chart.Detach(); } //+------------------------------------------------------------------+ //|| //+------------------------------------------------------------------+ # Define connection (_rate) \( "Open:" + Double to string (rates[_rate].open, number) + \ "; High: " + Double to string (rates[_rate].high, number) + \ "; Low: " + Double to string (rates[_rate].low, number) + \ "; Close: " + Double to string (rates[_rate].close, number) + "." ) //+--------------------------------------------------------------------------------+ //|Expert Tick Function| //+----------------------------------------------------------------+ Blank Tick () { Mql rates rate[]; integer number = ( integer ) symbol information integer ( _symbol , SYMBOL_DIGITS ); static datetime time = 0 ; datetime c time; static boolean first run = true ; boolean trigger = false ; if ( copy rate ( void , PERIOD_CURRENT , 0 , 2 , rate)!= 2 ) return ; display.setText(connect( 1 )); c time = rate[ 0 ]. time; if (cTime != time) { if (!firstRun) { display.push(); display.setText(connect( 0 )); } time = c time; first run = false ; trigger = true ; } if (outType == otLabels && Optimize Update) { if (triggered) display.update(); other dynamic conversions (display).updateOne(); } Other display.update(); } //+------------------------------------------------------------------+
To update the top row, you need to call the setText method of the class you are using. To move the text to the following line, you can use the push method using the class which is called . To display the added/updated text on the display, use the update method of any class. In addition to this method, the label display class has an additional method updateOne, which can speed up the display by more than 2 times. It is called only when the top row needs to be updated. If the push method is called, then after it you should call the update method instead of update one .
and output type you can choose display type canvas or label values. These n lines of changes set the number of rows that will be saved after scrolling via the push method. This optimizes the update. If the Push method has not yet been called, only one row can be updated economically, so the remaining rows do not need to be updated (see above). and width you can set the width of the display (relevant for canvases and labels using background). With the lY_distance parameter the desired font size can be achieved. The font size is taken from the lY_distance , subtracting the fDec coefficient setting from it. This allows the actual line height, rather than the font size, to be changed, regardless of the distance between lines. This back parameter enables background label mode .
Therefore, information can be displayed in charts in 5 different modes.
Using background in outType : label mode provides roughly the same payload as using other attached chart objects. That is, it slightly increases the time required to output text to the display.
Attachment download
📎 chartdisplay.mqh (12.77 KB)
📎 demo.mq5 (9.48 KB)
📎 chartdisplay.mqh (12.97 KB)
📎 canvasvslabels.mq5 (15.2 KB)
📎 canvasvslabelstester.mq5 (13.6 KB)
Source: MQL5 #33898
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •