Discussion of article "Statistical Distributions in MQL5 - taking the best of R" - page 11

 
Is this only in the five? Are there plans for a four?
 
Stanislav Korotky:
Is this only in the five? Is it planned for 4?

So everything should work in MT4. It is a standard OBJ_BITMAP_LABEL + custom Resource.

By the way, MT4 compiler is smarter than MT5

// MT5 is silent, MT4 warns - check operator precedence for possible error; use parentheses to clarify precedence Canvas.mqh
m_pixels[y*m_width+x]=(r<<16|g<<8|b<<0|255<<24) &0xffffffff;


And a bug has appeared (it doesn't work in MT5, but it works in MT4).

#property strict

#include <Graphics/Graphic.mqh>

double Func1(double x) { return MathPow(x,2); }
double Func2(double x) { return MathPow(x,3); }
double Func3(double x) { return MathPow(x,4); }

void SaveObjects( const long chart_id = 0, const int SubWindow = -1 )
{
  const int Total = ObjectsTotal(chart_id, SubWindow, OBJ_BITMAP_LABEL);
  
  for (int i = 0; i < Total; i++)
  {
    const string Name = ObjectName(chart_id, i, SubWindow, OBJ_BITMAP_LABEL);

    string ResourceName;
    
    if (ObjectGetString(chart_id, Name, OBJPROP_BMPFILE, 0, ResourceName))
      ResourceSave(ResourceName, Name + ".bmp"); // MT5 - false, MT4 - true
  }
}

void OnStart()
  {
   GraphPlot(Func1,Func2,Func3,-2,2,0.05,CURVE_LINES);
      
   SaveObjects();
  }
 
Make the correction.
//+------------------------------------------------------------------+
//| Update object on screen (redraw)|
//+------------------------------------------------------------------+
void CCanvas::Update(const bool redraw)
  {
//--- check
   if(m_rcname==NULL)
      return;
//--- update resource and redraw
   if(ResourceCreate(m_rcname,m_pixels,m_width,m_height,0,0,0,m_format) && redraw)
      ChartRedraw(this.m_chart_id);
  }
 

This is where

//+------------------------------------------------------------------+
//| Draw Wu's polyline|
//+------------------------------------------------------------------+
void CCanvas::PolylineWu(int &x[],int &y[],const uint clr,const uint style=UINT_MAX);

there are divisions by zero.

 
If the array has a length greater than the width (in pixels) of the chart, bummer.
 

I ask you to improve CGraphic and CCurve. They are weak classes. And it is almost impossible to inherit from them, because what you need is private. It took me a long time to get into it, but I had to rewrite the classes myself to make them work properly.

I wanted to make an interactive tick chart - it came out only crudely (without rewriting classes)

#include <Graphics/Graphic.mqh>

void GetPrices( double &Bids[], double &Asks[], const int Count = 100 )
{
  MqlTick Ticks[];
  
  const int Amount = CopyTicks(_Symbol, Ticks, COPY_TICKS_INFO, 0, Count);
  
  ArrayResize(Bids, Amount);
  ArrayResize(Asks, Amount);
  
  for (int i = 0; i < Amount; i++)
  {
    Bids[i] = Ticks[i].bid;
    Asks[i] = Ticks[i].ask;
  }
}

CGraphic* Graphic = new CGraphic;
const string Name = "Graphic" +(string)(GetTickCount() + MathRand());

void OnDeinit( const int Reason )
{
  Graphic.Destroy();
  delete Graphic;
  
  ChartRedraw();
}

void GraphTicks( const double &Price1[], const double &Price2[] )
{
   Graphic.Destroy();
   delete Graphic;

   Graphic = new CGraphic;  
   Graphic.Create(0, Name, 0, 0, 0, (int)(ChartGetInteger(0, CHART_WIDTH_IN_PIXELS) * 0.8), (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS));

   Graphic.AddCurve(Price1, CURVE_LINES);
   Graphic.AddCurve(Price2, CURVE_LINES);
  
   Graphic.PlotAllCurves();
   Graphic.Update();
}

void OnTick()
{
  double Bids[], Asks[];
  GetPrices(Bids, Asks);
  
  GraphTicks(Bids, Asks);
}

No DeleteCurve, ChangeCurve, etc.

 
fxsaber:

I ask you to improve CGraphic and CCurve. They are weak classes. And it is almost impossible to inherit from them, because what you need is private. It took me a long time to get into it, but I had to rewrite the classes myself to make them work properly.

I wanted to make an interactive tick chart - it came out only crudely (without rewriting classes)

#include <Graphics/Graphic.mqh>

void GetPrices( double &Bids[], double &Asks[], const int Count = 100 )
{
  MqlTick Ticks[];
  
  const int Amount = CopyTicks(_Symbol, Ticks, COPY_TICKS_INFO, 0, Count);
  
  ArrayResize(Bids, Amount);
  ArrayResize(Asks, Amount);
  
  for (int i = 0; i < Amount; i++)
  {
    Bids[i] = Ticks[i].bid;
    Asks[i] = Ticks[i].ask;
  }
}

CGraphic* Graphic = new CGraphic;
const string Name = "Graphic" +(string)(GetTickCount() + MathRand());

void OnDeinit( const int Reason )
{
  Graphic.Destroy();
  delete Graphic;
  
  ChartRedraw();
}

void GraphTicks( const double &Price1[], const double &Price2[] )
{
   Graphic.Destroy();
   delete Graphic;

   Graphic = new CGraphic;  
   Graphic.Create(0, Name, 0, 0, 0, (int)(ChartGetInteger(0, CHART_WIDTH_IN_PIXELS) * 0.8), (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS));

   Graphic.AddCurve(Price1, CURVE_LINES);
   Graphic.AddCurve(Price2, CURVE_LINES);
  
   Graphic.PlotAllCurves();
   Graphic.Update();
}

void OnTick()
{
  double Bids[], Asks[];
  GetPrices(Bids, Asks);
  
  GraphTicks(Bids, Asks);
}

No DeleteCurve, ChangeCurve, etc.

Is this such a short code? For some reason, I thought it was a sheet. Is it possible to make a visualisation of a stack with a given number of bands combined with a tape of trades? as I showed an example of visualisation in another software.
 
Stanislav Korotky:
Is this only in the five? Are there plans for a four?

Just the five.

The four is done.

 
ivanivan_11:
Is this such a short code? For some reason I thought it was a sheet. Is it possible to make a visualisation of a stack with a given number of bands, combined with a tape of trades? As I showed an example of visualisation in another software.

It has been possible to interactively draw anything for many years. Only nobody (publicly for sure) uses it.

The code is not short, but long and very crooked (as well as the result - flickers). The library needs to be seriously improved.

 

Yes, the library is still just a test run.

We will tidy it up, allow inheritance, add methods and get rid of crashes due to incorrect indexing.