Possibilities of Canvas. - page 4

 

Forum on trading, automated trading systems and testing trading strategies

Libraries: Easy Canvas

Nikolai Semko , 2020.02.17 05:15

I want to make it clear to the interested programmers the important point in how the canvas works in tester mode.
I was approached by a well-known programmer in this community with this question:

- Why, in the tester mode, the panel created on the objects is redrawn an order of magnitude faster than the one implemented on the canvas, while in normal mode, is everything okay with the canvas speed?

Having understood, I understood the reason and the solution to this problem.

The fact is that with objects, redrawing occurs along with redrawing the entire screen, and the screen in the tester is redrawn no more than 30 frames per second.

Objects are ultimately the same canvas (internal), but when you change the properties of the object , the canvas of the object is not formed (not recounted), but only formed at the time the screen is updated (ChartRedraw), which happens in the tester (and in the usual mode, too) no more often than our eyes can distinguish changes, i.e. no more than ~ 32 frames per second.

Let's say the panel changes every tick. Then, in the tester, by default, the canvas will be recounted every tick, but redrawing in the tester will still occur no more often than ~ 30 milliseconds (~ 30 frames per second).

In other words, the canvas will be recounted much more often than it will actually be displayed on the screen, therefore, a disproportionate waste of resources occurs.

The solution to this problem is to control the recalculation and redrawing of canvas not more than once every 15-30 milliseconds of computer time, then there will be no extra cycles of empty counts.

For example, like this:

 void OnTick ()
  {
   static uint lastCalc= 0 ;
   uint cur= GetTickCount ();
   if (cur-lastCalc> 15 ) {
    ReDrawMyCanvas();
    lastCalc=cur;
   }
  }

 
Sergey Golubev:

@Nikolai Semko is really the Master of Canvas. Great work !
 
@Nikolai Semko Excellent :) +++ 
 
Alain Verleyen:
@Nikolai Semko is really the Master of Canvas. Great work !
Lorentzos Roussos:
@Nikolai Semko Excellent :) +++ 
Sergey Golubev:

Thanks!
Yes, although it is simple and obvious now, but it is really a valuable find, especially for market products.

The incorrect operation of canvas in the tester was a big problem for its use in products for the market.
And now, thanks to a correctly posed question, this problem has already ceased to be a problem. ))



 

Thank you for the cool canvas indicator.

When want zoom in, back to max zoom out.

How in order to can be normal zoom?

Thank you.

 
ftakziroh #:

Thank you for the cool canvas indicator.

When want zoom in, back to max zoom out.

How in order to can be normal zoom?

Thank you.

What indicator are you talking about?
 

Multi MA Indicator.

I tried to zoom in and then back to max zoom out again automatically. 

 
ftakziroh #:

Multi MA Indicator.

I tried to zoom in and then back to max zoom out again automatically. 

Are you talking about this indicator?

What does zoom mean?

Press M to modify
Mouse click - stop  modify

Files:
3DMa.mq5  12 kb
iCanvas_CB.mqh  57 kb
Reason: