How to fix flickering bitmap when updating its size accordingly? - page 4

 
Alain Verleyen #:

Of course it matters. Anyway that's enough, if you want to be right, ok you are right.

I am more interested by this flickering, do you see it (it's a GIF, click on it) ? Do you know how to fix it ? 

These are questions not for me, but for MQ.

I don’t know why they have two CHARTEVENT_CHART_CHANGE events when switching focus to a window. If you catch the first CHARTEVENT_CHART_CHANGE since switching to the window and ignore this event, then this will be a fix.

For example, this can be solved by adding one check:

void Draw() {
   if(W.ChangeActive) return;
   Canvas.Erase(0x00FFFFFF);
   Canvas.FillRectangle((int)(Canvas.X(114.0)),(int)(Canvas.Y(iHigh(_Symbol,0,114))),(int)(Canvas.X(97.0)),(int)(Canvas.Y(iLow(_Symbol,0,97))),0x500000FF);
   Canvas.FillRectangle((int)(Canvas.X(50.0)),(int)(Canvas.Y(iHigh(_Symbol,0,50))),(int)(Canvas.X(5.0)),(int)(Canvas.Y(iLow(_Symbol,0,5))),0x50FF0000);
   Canvas.Update();
}
 
Alain Verleyen #:

There is an issue with your code. It's not always precise and reliable ! The top left corner is supposed to be at the high of candle 50 right ? But it is not, there is a small shift almost always present :

And sometimes a big shift :


Alain Verleyen #:

And also issue on the X axis :

Same rectangle, I just moved the chart horizontally.

Yes thank you. I moved the calculations one pixel to the left and up. Now it seems to match.

This error was because I thought that the center of the leftmost bar was a zero pixel, but it turned out to be -1.

Files:
iCanvas_CB.mqh  71 kb
 
Nikolai Semko #:

Yes thank you. I moved the calculations one pixel to the left and up. Now it seems to match.

This error was because I thought that the center of the leftmost bar was a zero pixel, but it turned out to be -1.

This applies only for MT5. In MT4 it is correct. When i firstly faced that, i placed the bitmap in the position (-1,-1) instead of the (0,0) and later i changed it to subtract 1 in the pixel calculation. i suppose that is easier than remember to shift the bitmap position.

 
Nikolai Semko #:

No!


And why did you insert my library into your code?

What didn't you like about one line of code:

 instead of 900 lines of code?



But I must say that your logic and code are very far from perfect. I would never do that. Study, study and study again. I advise you to forget about operations with strings, if this is not done directly to generate a string for output (for Print or Comment)

" And why did you insert my library into your code?"

I have no personal issue with your code.

I merged your library with my code is because I'm planning to sell a product in MQL5 apps store. MQL5 apps store can only accept a single MQL5 file without any external separated) 3rd party library like yours. I hope you're aware of this.

 
Agustinus Biotamalo Lumbantoruan #:

" And why did you insert my library into your code?"

I have no personal issue with your code.

I merged your library with my code is because I'm planning to sell a product in MQL5 apps store. MQL5 apps store can only accept a single MQL5 file without any external separated) 3rd party library like yours. I hope you're aware of this.

Please remember that using other peoples' code for commercial use requires obtaining authorisation from the author of that code, otherwise you would be infringing on copyright laws.

Usually publicly shared code only allows personal use and not commercial use.

Did you take the time to contact @Nikolai Semko and find out what usage rights are allowed and obtain authorisation if need be?

 
Nikolai Semko #:

Yes thank you. I moved the calculations one pixel to the left and up. Now it seems to match.

This error was because I thought that the center of the leftmost bar was a zero pixel, but it turned out to be -1.

I'm getting stackover flow error when using the latest library.

Could you please help take a look what's the issue is?

Thank you

#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com/en/users/abiotamalo"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#include <Canvas\iCanvas_CB.mqh>
#include <Canvas\Canvas.mqh>
CCanvas canvasObjects[];
int Counter=0;
void OnDeinit(const int r){
   for(int i=0;i<ArraySize(canvasObjects);i++){
         CCanvas c=canvasObjects[i];
         //c.Destroy();//This alone doesn't work
         Print(c.ChartObjectName());
         ObjectDelete(0,c.ChartObjectName()); 
         ChartRedraw();          
   }   
}
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create canvas
   int x=0;
   int y=0;
   ChartTimePriceToXY(0,0,iTime(Symbol(),PERIOD_CURRENT,144),iHigh(Symbol(),PERIOD_CURRENT,144),x,y);
   int x1=0;
   int y1=0;
   ChartTimePriceToXY(0,0,iTime(Symbol(),PERIOD_CURRENT,97),iLow(Symbol(),PERIOD_CURRENT,97),x1,y1);
   double priceWidth=x1-x;
   double priceHeight=y1-y;
   bool objCreated=false;
   /*
      First canvas object
   */
   if(true)
     {
      CCanvas canvas;
      string name="144_97";
      datetime startTime=iTime(Symbol(),PERIOD_CURRENT,50);
      double startignPoint=iHigh(Symbol(),PERIOD_CURRENT,50);        
      objCreated=canvas.CreateBitmap(name,startTime,startignPoint,x1-x,y1-y,COLOR_FORMAT_ARGB_NORMALIZE);
      canvas.Erase(ColorToARGB(clrRed, 0));      
      canvas.Update();
      ArrayResize(canvasObjects,2);
      canvasObjects[0]=canvas;  
      Print(canvas.ChartObjectName());   
     }
   ChartTimePriceToXY(0,0,iTime(Symbol(),PERIOD_CURRENT,50),iHigh(Symbol(),PERIOD_CURRENT,50),x,y);
   x1=0;
   y1=0;
   ChartTimePriceToXY(0,0,iTime(Symbol(),PERIOD_CURRENT,8),iLow(Symbol(),PERIOD_CURRENT,8),x1,y1);
   priceWidth=x1-x;
   priceHeight=y1-y;
   objCreated=false;
   /*
      Second Canvas Object
   */
   if(true)
     {
      CCanvas canvas;
      string name="50_8";
      datetime startTime=iTime(Symbol(),PERIOD_CURRENT,50);
      double startignPoint=iHigh(Symbol(),PERIOD_CURRENT,50);        
      objCreated=canvas.CreateBitmap(name,startTime,startignPoint,x1-x,y1-y,COLOR_FORMAT_ARGB_NORMALIZE);
      canvas.Erase(ColorToARGB(clrRed, 0));      
      canvas.Update();
      ArrayResize(canvasObjects,2);
      canvasObjects[1]=canvas;  
      Print(canvas.ChartObjectName()); 
     }    
   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 rates_total;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if (sparam=="0") W.MouseStatus=NO_PRESSED;
   else if (sparam=="1") W.MouseStatus=LEFT_BUTTON_PRESSED;
   else if (sparam=="2") W.MouseStatus=RIGHT_BUTTON_PRESSED;
   else if (sparam=="3") W.MouseStatus=LEFT_AND_RIGHT_BUTTONS_PRESSED;
   else W.MouseStatus=KEY_PRESSED;
   W.IdEvent=id;
   W.lparam=lparam;
   if(id==CHARTEVENT_CHART_CHANGE) ChartChanged();
   if(id==CHARTEVENT_MOUSE_MOVE) {
      W.MouseX=(int)lparam;
      W.MouseY=(int)dparam;
      W.MouseBar=(double)W.Left_bar+1-(double)W.MouseX/W.dx_pix;
      W.MouseSubWin=XYToTimePrice(W.MouseX,W.MouseY,W.MouseTime,W.MousePrice,id);
      if(W.MouseSubWin>0) for(int i=0; i<W.MouseSubWin; i++) W.MouseY=W.MouseY-W.height[i]-2;
   }
   if(OnZ) SetOnChart(sizeArr);
   if(OnChart) MyChartEvent(id,lparam,dparam,sparam);  
   if(id==CHARTEVENT_CHART_CHANGE)
     {
      for(int i=0;i<ArraySize(canvasObjects);i++){
         CCanvas c=canvasObjects[i];
         string name=c.ChartObjectName();
         string split[];
         StringSplit(name,StringGetCharacter("_",0),split);
         int startIndex=(int)split[0];
         int endIndex=(int)split[1];
         int x=(int)_X((double)startIndex);
         int y=(int)_Y(iHigh(Symbol(),PERIOD_CURRENT,startIndex));
         datetime startTime=iTime(Symbol(),PERIOD_CURRENT,startIndex);
         double startignPoint=iHigh(Symbol(),PERIOD_CURRENT,startIndex);         
         int x1=(int)_X((double)endIndex);
         int y1=(int)_Y(iLow(Symbol(),PERIOD_CURRENT,endIndex));
         double priceWidth=x1-x;
         double priceHeight=y1-y;  
         double fillRectangleSize=priceHeight/3;
         bool objCreated=c.CreateBitmap(name,startTime,startignPoint,x1-x,y1-y,COLOR_FORMAT_ARGB_NORMALIZE);
         if(i==0)
            c.FillRectangle(0,0,(int)priceWidth,(int)fillRectangleSize,ColorToARGB(clrRed, 50));
         if(i==1)
            c.FillRectangle(0,0,(int)(priceWidth*0.33),(int)fillRectangleSize,ColorToARGB(clrRed, 50));
         if(i==0)//Just width variation
            c.FillRectangle(0,(int)fillRectangleSize,(int)(priceWidth*0.5),(int)fillRectangleSize*2,ColorToARGB(clrGreen, 50));
         else
            c.FillRectangle(0,(int)fillRectangleSize,(int)(priceWidth*0.2),(int)fillRectangleSize*2,ColorToARGB(clrGreen, 50));
         c.FillRectangle(0,(int)fillRectangleSize*2,(int)priceWidth,(int)fillRectangleSize*3,ColorToARGB(clrBlue, 50));
         //c.Resize(priceWidth*0.1,fillRectangleSize*0.1);
         c.Update();     
      }   
     }
  }    
 
Fernando Carreiro #:

Please remember that using other peoples' code for commercial use requires obtaining authorisation from the author of that code, otherwise you would be infringing on copyright laws.

Usually publicly shared code only allows personal use and not commercial use.

Did you take the time to contact @Nikolai Semko and find out what usage rights are allowed and obtain authorisation if need be?

ahh noted, i didn't know that.

I have not sold anything with his code yet. I will contact him for authorization.


Thanks!

 
Fernando Carreiro #:

Please remember that using other peoples' code for commercial use requires obtaining authorisation from the author of that code, otherwise you would be infringing on copyright laws.

Usually publicly shared code only allows personal use and not commercial use.

Did you take the time to contact @Nikolai Semko and find out what usage rights are allowed and obtain authorisation if need be?

Oh no.  I don't mind others using my code, including for commercial purposes.  That's why I'm publishing the code so that others can use it.  The essence of my complaint was that my library code was not just inserted into the working main code of the indicator, but was also mixed, as a result of which the code became unreadable and unworkable, since the logic of operation was broken.  It’s just that Agustinus, as I understand it, thinks that if he includes the mqh library, the market will not miss it.  It's a delusion.  After all, there will be only one ex5 file.
 
Nikolai Semko #:
Oh no.  I don't mind others using my code, including for commercial purposes.  That's why I'm publishing the code so that others can use it.  The essence of my complaint was that my library code was not just inserted into the working main code of the indicator, but was also mixed, as a result of which the code became unreadable and unworkable, since the logic of operation was broken.  It’s just that Agustinus, as I understand it, thinks that if he includes the mqh library, the market will not miss it.  It's a delusion.  After all, there will be only one ex5 file.

Thank you @Nikolai Semko!

I really appreciate for your support and your hard work to the MQL5 community.

Other than that, God bless you!

 
Agustinus Biotamalo Lumbantoruan #:

I'm getting stackover flow error when using the latest library.

Could you please help take a look what's the issue is?

Thank you

Hey @Nikolai Semko, do you know why I get stack over flow error when use the library?

Thanks