Discussion of article "Developing custom indicators using CCanvas class" - page 2

 
fxsaber:

That's good news! What's the idea? Instead of a tick history, a custom time series?

No. Draw a histogram of tick rate next to the tick history.

So that, playing with the parameters, you can visually determine the periods of activity and, perhaps, find some patterns.

 
Dennis Kirichenko:

Good topic. Thanks to the author, will be making a tick indicator on canvas.....

I noticed this.

There is a private data member m_canvas_name, but the method that sets its value - Name() - is public. Imho, the encapsulation principle is violated. I will make this method private.

Maybe protected ? Because all the others inherit CCanvasBase. And then it will be impossible to use this method in them. Although I do not know, maybe you have changed something else in the general structure.

 
Alexander Fedosov:

Maybe protected ? Because all the others inherit CCanvasBase. And then you can't use this method in them. Although I don't know, maybe you have changed something else in the general structure.


So yes, protected.

Then here:

bool CCanvasBase::DeleteCanvas()
  {
   return(ObjectDelete(0,m_canvas_name)?true:false);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialisation function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ind.Delete();
   ChartRedraw();
  }

Why so complicated in the indicator? Imho, it is necessary to clean up the canvas itself. I would add ChartRedraw() to the DeleteCanvas() method.

 
fxsaber:

When you have sketches, please send screenshots/video. I posted such an indicator myself, but it did not go to the people. Although I haven't found a better one. It's interesting to see other solutions on kanvas.


I'm making one for FORTS. I made it in the usual format, but in the Tester it works like hell when called from the EA body. Now I will transfer all the code to the EA...

 
Dennis Kirichenko:

Yeah, that's right.

Then here:

Why so complicated in the indicator? In my opinion, it is necessary to clean up the canvas itself. I would add ChartRedraw() to the DeleteCanvas() method.

Yes, this way there will be less unnecessary lines. We make the canvas neat and send the redraw there.

 

That's not really the way to do it:

//+------------------------------------------------------------------+
//|| Deletes a graphics resource|
//+------------------------------------------------------------------+
bool CCanvasBase::DeleteCanvas()
  {
   return(ObjectDelete(0,m_canvas_name)?true:false);
  }

Why a ternary operator? - When you can just do it:

//+------------------------------------------------------------------+
//|| Deletes a graphics resource|
//+------------------------------------------------------------------+
bool CCanvasBase::DeleteCanvas()
  {
   return ObjectDelete(0,m_canvas_name);
  }

I did it this way:

//+------------------------------------------------------------------+
//|| Deletes a graphics resource|
//+------------------------------------------------------------------+
bool CCanvasBase::DeleteCanvas()
  {
   if(ObjectFind(0,m_canvas_name)>-1)
      if(ObjectDelete(0,m_canvas_name))
        {
         ChartRedraw();
         return true;
        }
   return false;
  }


But canvas has its own method of deleting CCanvas::Destroy().

Why do we need to add something else?

 

I have a problem with vertical scaling.

I want to make a tick chart on RTS, where the maximum on the Y axis is 97784.0 and the minimum is 97756.0.

I do this in the code:

//--- update the chart
double min_y=NormalizeDouble(min_pr-0.2*diff,_Digits);
double max_y=NormalizeDouble(max_pr+0.2*diff,_Digits);
ticks_ind.YMin(min_y);
ticks_ind.YMax(max_y);
ticks_ind.SetArrayValue(prices);


I get this:

https://www.mql5.com/ru/charts/7227612/rts-9-17-m1-ao-otkritie-broker

The minimum is shown correctly, but then there is some whizzing.

Apparently, the CLineGraph::VerticalScale() method is not as fine-tuned as I think, or worse, as it should be.

График RTS-9.17, M1, 2017.06.19 15:22 UTC, АО ''Открытие Брокер'', MetaTrader 5, Real
График RTS-9.17, M1, 2017.06.19 15:22 UTC, АО ''Открытие Брокер'', MetaTrader 5, Real
  • www.mql5.com
Символ: RTS-9.17. Период графика: M1. Брокер: АО ''Открытие Брокер''. Торговая платформа: MetaTrader 5. Режим торговли: Real. Дата: 2017.06.19 15:22 UTC.
 
Документация по MQL5: Стандартная библиотека / Научные графики / CGraphic
Документация по MQL5: Стандартная библиотека / Научные графики / CGraphic
  • www.mql5.com
Стандартная библиотека / Научные графики / CGraphic - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

Anatoly, thanks for the tip, I will use it. It's a shame that the idea turns out to be unfriendly code...