Errors, bugs, questions - page 2801

 
Roman:

Try just Print(

And printf seems to work too.
In printf, the first parameter specifies the type of value to be printed.


Print works! Thank you! ))

But printf does not always work


 

I want to display one character on the canvas and move it, source:

#property indicator_chart_window
#property indicator_plots 0

#include <Canvas\Canvas.mqh>


CCanvas canvas;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   canvas.CreateBitmapLabel(ChartID(), 0, "canvas", 0, 0, 900, 400);
   canvas.FontSet("Courier New", 32);
   canvas.Erase(0);
   canvas.Update();
   EventSetMillisecondTimer(250);
//---
   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[])
{
//---

//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
{
   static int x = 0;
   static const uint col_black = ColorToARGB(clrBlack);
   static const uint col_red = ColorToARGB(clrRed);
   canvas.TextOut(x, 100, "S", col_black);
   x+=10;
   canvas.TextOut(x, 100, "S", col_red);
   canvas.Update();
}
//+------------------------------------------------------------------+


why do i overwrite the previous rendered image with black and artifacts remain ?


 
Igor Makanu:

I want to display one character on the canvas and move it, source:


why do i overwrite the previous rendered image with black and still have artifacts ?


It's better to re-fill the whole kanvas at once. It's better to redraw the whole kanvas at once.

 
Andrey Barinov:

It's better to re-fill the whole canva at once. It's all redrawn afterwards anyway.

I've already thought about it, but the question is purely technical

it turns out that the antialiasing of fonts works? and the goal is to move the sprites, in general, I want to understand why it works so

 

I don't know where to dig, can anyone suggest a direction for searching. I'm writing an indicator, but after the first click on "compile", the calculation part gives out nonsense, I compile again, it seems to be true.

2020.07.13 14:12:05.987 ZigZag_MP (USDJPY,M15)  Average wave size = -2147483648 points; less then average: 1/100 min=99999999.0 max=107.1 steps=-2147483648
2020.07.13 14:12:27.179 ZigZag_MP (USDJPY,M15)  Average wave size = 273 points; less then average: 65/100 min=106.422 max=107.848 steps=57

2020.07.13 14:18:38.001 ZigZag_MP (USDJPY,M15)  Average wave size = -2147483648 points; less then average: 1/100 min=99999999.0 max=107.1 steps=-2147483648
2020.07.13 14:18:46.751 ZigZag_MP (USDJPY,M15)  Average wave size = 273 points; less then average: 65/100 min=106.422 max=107.848 steps=57

I don't do anything extraordinary - I just calculate the last 100 Zig-Zag knees. I reversed the code more than once, but the thing is, it is the same, but the result is different.

Anticipating one of the possible versions: indicator buffers are forced initialized, there is no rubbish in them.

 
Igor Zakharov:

anticipating one of the possible versions: indicator buffers are forcibly initialised, there is no rubbish in them.

the question is where do you initialize

if prev_calculated == 0, then everything is OK, if it is in OnInt(), then it will glitch when switching TF and during compilation

 
Igor Makanu:

The question is where do you initialize

if by prev_calculated == 0 , then everything is ok, if in OnInt() , then it will glitch when switching TF and when compiling

tried all variants (both onInt and oncalculated); the current one: in the loop each value is individually assigned. i checked through the data window - no weird/trash values.

 
Igor Makanu:

I want to display one character on the canvas and move it, source:


Why am I mashing the previous rendered image in black and artifacts remain ?


It's because of anti-aliasing. The surest way is to draw a rectangle in the background colour, on top of the symbol. And then output the symbol with the new coordinates. That's how it's usually done in cases like this.

 
Igor Makanu:
Mihail Matkovskij:

This is because of anti-aliasing. The surest way is to draw a rectangle in the background colour, on top of the symbol. And then output the symbol with the new coordinates. This is what is usually done in cases like this.

Do not forget about simple moving kanvas without any redrawing and painting.
This is the quickest way of moving.

#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164

void OnStart() {
// Формируем какой-то фон
   for (int i = 0; i<1000; i++) Canvas.Circle(rand()%2048, rand()%2048,50+rand()%50,ARGB(255,rand()%256,rand()%256,rand()%256));
   Canvas.Update();
// -----------------------
   int x=100, y=100;
   iCanvas c(0,x,y,"symbol",50,50); // создаем дополнительный канвас размером 50х50
   c.TextPosition(0,0);
   c.CurentFont("Tahoma",50);
   c.Comm("S");
   c.Update();
   while(!IsStopped()&& x<W.Height) {
      c.MoveCanvas(++x,++y);        // перемещаем данный канвас
      c.Update();
      Sleep(50);
   }
}
 
Nikolai Semko:

Don't forget the ability to simply move the kanvas without all the redrawing and overpainting.
This is the fastest way to move.

No one is denying it. It's just that there is a concept where there is a single screen as a canvas. In turn, the same custom canvas (array of pixels) is drawn on a window canvas (chart). More precisely, it is first passed to the chart (copied) using ResourceCreate (in OBJ_BITMAP or OBJ_BITMAP_LABEL). In the chart window, everything is drawn using Win API (if I'm not mistaken). Although, it can be done using other API as well. But the CCanvas class has its own methods of drawing on elements of the m_pixels array.

It turns out, drawing a small rectangle then you still have to pass a lot of pixels usingResourceCreate (saves time only on drawing). And this way you can simply moveOBJ_BITMAP_LABEL around the chart, without processing the m_pixels array and then copying it to OBJ_BITMAP_LABEL.
Reason: