Canvas is cool! - page 83

 

Thanks to everyone who is suggesting a solution. I need some time to test everything and apply it to my products. What can work on simple products, I need to test on more complex ones. The timer idea is really top. Doesn't solve all the problems, but it solves other issues I've encountered.

Not ignoring anyone. I'll be able to respond next week with what worked, what didn't.

 
Canvas based indicators: Filling channels with transparency
Canvas based indicators: Filling channels with transparency
  • www.mql5.com
In this article I'll introduce a method for creating custom indicators whose drawings are made using the class CCanvas from standard library and see charts properties for coordinates conversion. I'll approach specially indicators which need to fill the area between two lines using transparency.
 
Nikolai Semko #:

Yeah, there's just one little undocumented nuance.
If you use alpha-channel (COLOR_FORMAT_ARGB_NORMALIZE), you must fill it not with zeros before creating your bitmap.

otherwise the edges of the characters will be "jagged".

Thanks.


And thankyou for all your selfless work on Canvas.

I've learned alot and impementing canvas to to my non regular charts in mt4, (Renko for example)  which has replaced thousands of chart-objects.

 
Jon_G #:

Thanks.


And thankyou for all your selfless work on Canvas.

I've learned alot and impementing canvas to to my non regular charts in mt4, (Renko for example)  which has replaced thousands of chart-objects.

Thanks for the kind words.

Yes, thousands of objects start to incredibly slow down the interface.
This is a serious oversight of MetaQuotes.
A well-built canvas does not cause lags even with 10,000 virtual objects.

 

Code Base

PNG

Nikolai Semko, 2023.07.15 07:24

Forget about BMP files like a bad dream. With this library, you will now be able to use the more advanced and compact PNG image format for your programmes.

I have finally implemented c PNG.
I got the implementation from @Zorro(https://www.mql5.com/ru/forum/92113#comment_2672596)
Check it out please. I haven't had any glitches so far.



 
Nikolai Semko #:
Finally implemented c PNG.
.

Cool and useful. Just for interest, can it be used in MT4?

 
Vitaliy Kuznetsov #:

Cool and useful. Just out of interest, can this be used in MT4?

Sure
I'll give it a try. I think the code will remain almost the same.
 

Nikolai, have you found somewhere ready code on kanvas that allows to scroll the window?


 
Vitaliy Kuznetsov #:

Nikolai, have you found somewhere ready code on kanvas that allows to scroll the window?


Anatoly and Pyotr had implementations

But I haven't used it. That's why I can't judge.

 
I want to create a user interface with the Canvas class. My only problem is that I don't know how make the dashboard movable on chart.
I searched a lot but didn't find any example. I would appreciate if you could give a hint.


//+------------------------------------------------------------------+
//|                                                 Canvas Panel.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots   0

#include <Canvas\Canvas.mqh>
CCanvas  canvas;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create canvas
   if(!canvas.CreateBitmapLabel(0, 0, "Dashboard", 40, 40, 400, 200, COLOR_FORMAT_ARGB_NORMALIZE))
   {
      Print("Error creating canvas: ", GetLastError());
      return(INIT_FAILED);
   }
   
   canvas.Erase(ColorToARGB(clrGray, 200));
   canvas.Update(true);

   ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);

//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy application dialog
   canvas.Destroy();
   ChartRedraw();
}
//+------------------------------------------------------------------+
//| 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);
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{

}

//+------------------------------------------------------------------+
Files:
screenshot.png  18 kb