Discussion of article "Developing custom indicators using CCanvas class"

 

New article Developing custom indicators using CCanvas class has been published:

The article deals with developing custom graphical indicators using graphical primitives of the CCanvas class.

Unlike a simple arc indication, the sectional one looks as if it has labels separating equal intervals. When creating a layout of the indicator of this type, I have decided to make ten sections and add a new element – the inner frame. The basic structure with the arc sectional indication is presented in Fig. 5.

Fig. 5. Basic structure of the circular indicator with the arc sectional indication

Author: Alexander Fedosov

 

Thanks to the author for the article. I have noted a lot of simple (but at the same time elegant) solutions for myself, which I will definitely use in my programmes.

 
MetaQuotes Software Corp.:

Published article Creating custom indicators using CCanvas class:

Author: Alexander Fedosov


Oh, what a beauty! I add it to my memorial ;)
 

I would like to draw your attention once again to the fact that when applying several copies of the same indicator implemented using CustomGUI classes, the names in the Create() method must be different. As an example, the implementation is below.

#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0
//---
#include <CustomGUI\CustomGUI.mqh>
CCircleSection ind;
//+------------------------------------------------------------------+
//| Input parameters of the indicator|
//+------------------------------------------------------------------+
input ENUM_TIMEFRAMES   tf=PERIOD_CURRENT;
input int               period=10;
input int               indsize=50;
input ENUM_ORIENTATION  orient=VERTICAL;
input int               X=100;
input int               Y=100;
//---
int      IndHandle;
double   rsi[];
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- get indicator handle
   IndHandle=iRSI(Symbol(),tf,period,PRICE_CLOSE);
   if(IndHandle==INVALID_HANDLE)
     {
      Print("Failed to get indicator handle");
      return(INIT_FAILED);
     }
   ArraySetAsSeries(rsi,true);
//---
   ind.Radius(indsize);
   ind.LabelSize(15);
   ind.LabelValue("RSI "+"("+IntegerToString(period)+")");
   ind.Orientation(orient);
   ind.Create("rsi_custom"+IntegerToString(MathRand()),X,Y);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(CopyBuffer(IndHandle,0,0,1,rsi)<1)
      return(0);
   ind.NewValue(rsi[0]);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialisation function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ind.Delete();
   ChartRedraw();
  }
//+------------------------------------------------------------------+

The Create() method has a unique name.

Files:
 

thank you.

is it possible to implement in MT4 or MT5 the function of selecting an indicator object? (for example, a line).

For example, double-click on a line and it is highlighted with a bold line, the description of the line appears, and vice versa.

 
Ilmir Galiev:

thank you.

is it possible to implement in MT4 or MT5 the function of selecting an indicator object? (for example, a line).

For example, double-click on a line and it is highlighted with a bold line, the description of the line appears, and vice versa.

No. The essence of this method is that it is a picture that is redrawn when any conditions change. It does not react to hotkey or mouse click events.
 
Alexander Fedosov:
No. The essence of this method is that it is a picture that is redrawn when any conditions change. It doesn't respond to hotkey or mouse click events.

Oh, come on. What are mouse clicks? Not "changing any conditions". It generates an event, which is used to redraw the canvas as it should be. Ilmir, the correct answer to your question is of course you can.

 

Good topic. Thanks to the author, will be making a tick indicator on canvas.....

I noticed this.

//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
class CCanvasBase
  {
private:
   //--- Canvas name
   string            m_canvas_name;
   //--- Canvas coordinates
   int               m_x;
   int               m_y;
   //--- Canvas size
   int               m_x_size;
   int               m_y_size;
protected:
   CCanvas           m_canvas;
   //--- Creates a graphical resource for the object
   bool              CreateCanvas(void);
   //--- Deletes the graphics resource
   bool              DeleteCanvas(void);
public:
                     CCanvasBase(void);
                    ~CCanvasBase(void);
   //--- Sets and returns coordinates
   void              X(const int x)                         { m_x=x;                      }
   void              Y(const int y)                         { m_y=y;                      }
   int               X(void)                                { return(m_x);                }
   int               Y(void)                                { return(m_y);                }
   //--- Sets and returns dimensions
   void              XSize(const int x_size)                { m_x_size=x_size;            }
   void              YSize(const int y_size)                { m_y_size=y_size;            }
   int               XSize(void)                            { return(m_x_size);           }
   int               YSize(void)                            { return(m_y_size);           }
   //--- Sets the indicator name at creation
   void              Name(const string canvas_name) { m_canvas_name=canvas_name;  }
  };

There is a private data member m_canvas_name, but the method that sets its value - Name() - is public. Imho, the encapsulation principle is violated. I will make this method private.

 
Dennis Kirichenko:

Good topic. Thanks to the author, will be making a tick indicator on canvas....

As you have sketches, please send screenshots/video. I posted such an indicator myself, but it did not go to the people. Although I haven't found a better one. It is interesting to see other solutions on the canvas.

 
fxsaber:

I posted such an indicator myself, but it did not go to the people.

It did, it did.

I am even trying to make a tick speed indicator based on it.

 
Andrey Khatimlianskii:
Go, go, go.

I'm even trying to make a tick rate indicator based on it.

That's good news! What is the idea? Instead of tick history to substitute a custom time series?