How to make objects drawn by XY change smoothly (MT4 vs MT5) - page 3

 
Vitaliy Kuznetsov:

Is it possible to get tooltips (tooltips) differently when hovering the mouse over individual graphics elements?

I was tracking CHARTEVENT_MOUSE_MOVE and then using coordinates of mouse cursor, which are represented in Canvas by the whole set of data of any taste and colour:

   int               MouseX;      // coordinate X of the current position of the mouse pointer
   int               MouseY;      // coordinate Y of the current position of the mouse pointer
   double            MouseBar;    // the current bar position of the mouse pointer
   double            MousePrice;  // the current price of the mouse pointer
   datetime          MouseTime;   // the current time of the mouse pointer

I was calculating for which object a hint would be output:

input uint                    i_uFontSize                = 14;                                     // Размер шрифта в подсказках


#define   TOOLTIP_BGCOLOR                                             color(C'255,255,225') 

int g_nTooltipWidth = <ширина блока в пикселах>;
int g_nTooltipHeight = <высота блока в пикселах>;
int nY = <расчет положения левого верхнего угла для подсказки>;


         Canvas.FillRectangle(W.MouseX, nY, W.MouseX + g_nTooltipWidth, nY + g_nTooltipHeight, ColorToARGB(TOOLTIP_BGCOLOR));
         Canvas.Rectangle(W.MouseX, nY, W.MouseX + g_nTooltipWidth, nY + g_nTooltipHeight, ColorToARGB(clrBlack));
         Canvas.TextPosition(W.MouseX + 5, nY + 2);
         Canvas.CurentFont("Arial", i_uFontSize, i_uFontSize + 2, clrBlack);
         Canvas.Comm("<первая строка подсказки>");
         Canvas.Comm("<вторая строка подсказки>");
         Canvas.Comm("<третья строка подсказки>");
 
Nikolai Semko:

That's what I said.
I'm just wondering - can you do it yourself, and not just repeat my advice?
two of them are easy to output...
Code, please.
If you don't, I'll write it myself tomorrow when I wake up. But then I will call Fedoseev an idiot. ))

Did Fedoseyev just leak or something?
Didn't want to put it in brackets.
One of two things: too much pseudo-proudness or too little intelligence.
I knew it.
Got myself a new nickname.
 
Vitaliy Kuznetsov:


here is the longer way (not by much) that I talked about in the beginning without my library and that Fedoseev tried to give in to.
This is the better solution to your situation:

#property indicator_chart_window
#define  width 50
#define  height 10
#define  N 20

#property indicator_buffers 0
#property indicator_plots   0


string obj_name = "Asd_";
double max = 0;
double min = 0;
double w = 0;
double h = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
   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(prev_calculated != rates_total) {
      DrawObj();
   }
   return(rates_total);
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
   if(id == CHARTEVENT_CHART_CHANGE) {
      w = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
      h = (int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
      min = ChartGetDouble(0,CHART_PRICE_MIN);
      max = ChartGetDouble(0,CHART_PRICE_MAX);
      DrawObj();
   }
}
//+------------------------------------------------------------------+
//| Выводим на график                                                |
//+------------------------------------------------------------------+
void DrawObj() {
   string GenName = obj_name;
   double startPricePos = SymbolInfoDouble(Symbol(),SYMBOL_BID);
   double step_Pips = 50*_Point;
   double stp = -N*step_Pips;
   for(int i=-N; i<=20; i++, stp+=step_Pips) 
      RectLabelCreate(GenName+"UP_"+IntegerToString(i),startPricePos + stp);
   ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| Создает прямоугольную метку                                      |
//+------------------------------------------------------------------+
void RectLabelCreate(string name,   // имя метки
                     double price   // цена
                    ) {
   if (max==min) return;
   const long             chart_ID=0;               // ID графика
   int              sub_window=0;                   // номер подокна
   int              x=int(w/2);                     // координата по оси X
   int              y=int(h*(max-price)/(max-min)); // координата по оси Y

   const color            back_clr=C'236,233,216';  // цвет фона
   const ENUM_BORDER_TYPE border=BORDER_SUNKEN;     // тип границы
   const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER; // угол графика для привязки
   const color            clr=clrRed;               // цвет плоской границы (Flat)
   const ENUM_LINE_STYLE  style=STYLE_SOLID;        // стиль плоской границы
   const int              line_width=1;             // толщина плоской границы
   const bool             back=false;               // на заднем плане
   const bool             selection=false;          // выделить для перемещений
   const bool             hidden=true;              // скрыт в списке объектов
   const long             z_order=0;                // приоритет на нажатие мышью
   if(ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0)) {
      ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
      ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
      ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border);
      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
      ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
      ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
      ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width);
      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   } else Print("Error - " + string(_LastError));
}

Как сделать плавность изменения объектов, нарисованных по XY (MT4 vs MT5)
Как сделать плавность изменения объектов, нарисованных по XY (MT4 vs MT5)
  • 2021.07.19
  • www.mql5.com
Помогите решить проблему на терминале МТ5. Решил перевести свой продукт из mql4 в mql5...
 
Nikolai Semko:

here is the longer way (not much longer) that I talked about in the beginning without my library and that Fedoseev tried to give in to.
This is more correct solution in your situation:

But you have to understand that the problem with ChartGet functions asynchrony is not solved by this.
These functions now consume not 99.76% but a bit less - 99.1%.

If they were not asynchronous, then everything would move together with the chart, instead of lagging a little behind.

 

Even more impressed with this place:

 double stp = -N*step_Pips;
   for(int i=-N; i<=20; i++, stp+=step_Pips)
That's a lot of conceit. But you wouldn't even know what the joke of that humour is. It's embarrassing.
 
Nikolai Semko:
Did Fedoseyev merge or what?
Didn't want to put it out of brackets.
One of two things: too much pseudo-proudness or too little intelligence.
I knew it.
Got himself a new nickname.

You're gonna lose your fly, baby.

 
Vitaliy Kuznetsov:

Thank you for the examples! Very clear and informative, and not least quick.

All the graphics from the example on the kanvas in the object lists look like a single object.

Is it possible to get different tooltips (tooltips) when hovering the mouse on separate graphics items?

Or may I create a separate canvas object for each rectangle? Won't it affect the speed?

If you have some time, I'm waiting for an answer, maybe even a code sample.

You can use one canvas for each object instead of one.
It will even be a bit faster and the code won't be much bigger. At least less than with objects.
Kanvas is very fast. Objects are good too, as long as there are not too many of them. The bottleneck occurs when objects are several hundred or a thousand.
By the way, it is the same in JavaScript. There are also canvas and objects (html and CVG). Canvas always wins in speed and graphical capabilities, but loses in usability of control and management.
In JS, I myself have been actively mixing canvas and vector objects (html, css, svg), taking advantage of both.
But the real biggest problem in using canvas in MQL5 (as well as objects) is unbelievable dullness of ChartGet functions.
But this is if you are trying to bind to a price chart.
If you disable the entire chart and draw your own one, you won't have such a problem.

 
Dmitry Fedoseev:

Even more impressed by this place:

That's a lot of conceit. But you won't even know what the joke is. It's embarrassing.

It always amazes me when you're a local old timer, always trying to make something clever out of yourself.
So as not to be painfully painful for the wasted years.
But for some reason it only squeezes out a fart every time :))
 
Ihor Herasko:

I was tracking CHARTEVENT_MOUSE_MOVE and then using coordinates of mouse cursor, which are represented in Canvas by the whole set of data for all tastes and colours:

, calculate for which object a hint should be displayed:

Nikolai Semko:

you can use not one Canvas, but one for each object.
It will even be a bit faster and the code will not be much bigger. At least less than with objects.
Kanvas is very fast. Objects are good too, as long as there are not too many of them. The slowdown occurs when objects become several hundred or a thousand.

Thank you. I will try to test both variants.

 
Vitaliy Kuznetsov:

Thank you. I'll try to check both options.

Vitaly, what video editor do you use for YouTube?
Very cool!
Adobe Premiere Pro?