How to bind a canvas to a chart

 

I have created a canvas

DebugDraw()
{
      _width=(ushort)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
      _height=(ushort)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS); 
      ccanvas.CreateBitmapLabel(ChartID(), 0, "ccanvas", 0, 0, _width, _height, COLOR_FORMAT_ARGB_NORMALIZE);
}

And then I have drawn primitives

void Draw()
   {
      _width=(ushort)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
      _height=(ushort)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS); 
      
      int x;
      int y;
      
      ccanvas.Resize(_width, _height);
      
      int sizeticks = ArraySize(ticks);
      
      for(int i=0;i<sizeticks;i++)
      {
         ChartTimePriceToXY(ChartID(), 0, ticks[i].time, ticks[i].ask, x, y);
         ccanvas.FillCircle(x,y,1,ColorToARGB(clrRed));
      }
      
      ChartTimePriceToXY(ChartID(), 0, t1.dt, t1.price, x, y);
      ccanvas.LineHorizontal(x-500, x+500, y, ColorToARGB(clrRed));
      
      ChartTimePriceToXY(ChartID(), 0, t2.dt, t2.price, x, y);
      ccanvas.LineHorizontal(x-500, x+500, y, ColorToARGB(clrRed));
      
      ChartTimePriceToXY(ChartID(), 0, b1.dt, b1.price, x, y);
      ccanvas.LineHorizontal(x-500, x+500, y, ColorToARGB(clrRed));
      
      ChartTimePriceToXY(ChartID(), 0, b2.dt, b2.price, x, y);
      ccanvas.LineHorizontal(x-500, x+500, y, ColorToARGB(clrRed));
      
      ChartTimePriceToXY(ChartID(), 0, start.dt, start.price, x, y);
      ccanvas.LineVertical(x, y+500, y-500, ColorToARGB(clrRed));
      
      ccanvas.Update();
   }

I want to bind this canvas to the main chart because I have a problem when I try to do a vertical scale or a horizontal scroll. My primitives don't move with the main chart. How to fix it ?

Files:
help.jpg  146 kb
 

OnChartEvent() and CHARTEVENT_CHART_CHANGE should be used.

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id==CHARTEVENT_CHART_CHANGE)
      Draw();
  }
//+------------------------------------------------------------------+