Libraries: Easy Canvas - page 9

 
Will the library work in Strategy Tester? I want to try manual testing in the Strategy Tester.
 
jaffer wilson:
Will the library work in Strategy Tester? I want to try manual testing in the Strategy Tester.
Yes, it will. But you need to take care of a couple of things, because events in the tester don't work properly and not to overload the tester with canvas calculations because of higher time density.
I'll give an example a little later.
But for now you can have a look here.
https://www.mql5.com/en/forum/229521/page4#comment_15005864
Possibilities of Canvas.
Possibilities of Canvas.
  • 2020.01.18
  • www.mql5.com
Demonstration of the possibilities of Сanvas in dynamics. The picture never repeats. This script also works on MQL4, but much slower...
 
jaffer wilson:
Will the library work in Strategy Tester? I want to try manual testing in the Strategy Tester.
#property indicator_chart_window
#include <Canvas\iCanvas.mqh> //https://www.mql5.com/en/code/22164
//+------------------------------------------------------------------+
int max=0,min=0;
double Max=0,Min=0;
int OnInit() {
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
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[]) {
   max= ArrayMaximum(high,rates_total-W.Left_bar,W.BarsInWind);
   min= ArrayMinimum(low,rates_total-W.Left_bar,W.BarsInWind);
   Max=high[max];
   Min=low[min];
   max=rates_total-1-max;
   min=rates_total-1-min;
   if (rates_total>0) Draw();
   return(rates_total);
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // event identifier
                  const long& lparam,   // event parameter of long type
                  const double& dparam, // event parameter of double type
                  const string& sparam) { // event parameter of type string
   if (id==CHARTEVENT_MOUSE_MOVE) Draw(); 
}
//+------------------------------------------------------------------+
void Draw () {
   static double pr=0;
   static uint clr=0;
   static uint lastCalc=0;
   uint cur=GetTickCount();
   if (cur-lastCalc<30) return;
   lastCalc=cur; 
   double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
   if (Canvas.tester) ChartChanged();        // update chart parameters if in tester mode
   if (pr<Ask) clr=0x800000FF;               // red
   if (pr>Ask) clr=0x80FF0000;               // blue
   Canvas.Erase(clr);
   Canvas.FillCircle((int)Canvas.X(double(max)),(int)Canvas.Y(Max),20,0xAA50FF50);
   Canvas.FillCircle((int)Canvas.X(double(min)),(int)Canvas.Y(Min),20,0xAAFFFF50);
   Canvas.CurentFont("Tahoma",50,50,0xFF80FF80,0.4);
   Canvas.TextPosition(W.MouseX,W.MouseY);
   Canvas.Comm("Ask = " + DoubleToString(Ask,_Digits));
   Canvas.Comm("Bid = " + DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits));
   Canvas.Comm("Spread = " + DoubleToString((Ask-Bid)/_Point,0));
   Canvas.Update();
   pr=Ask;
}
//+------------------------------------------------------------------+

What is highlighted in yellow is what is necessary to reduce the load on the tester
What is highlighted in green is what is necessary to render coordinates correctly. Try removing this line and see what happens in the tester.

In this indicator the colour of the screen changes depending on the direction of price change, the minimum and maximum price on the screen is highlighted and text information about Bid and Ask in the current position of the mouse pointer is displayed.


But, unfortunately, in Tester the mouse movement event is executed only when the left mouse button is pressed.
This applies not only to my iCanvas class, but also to any graphical output in Tester.
Only I have a simpler way to implement it.
And even the GUI control works quite well:


 
Thank you very much for the reply and the example.
 
jaffer wilson:
Thank you very much for the answer and the example.
No problem
 

Hello,

very nice work. Thank you.

Can you please check the CanvasBar Sample? It won't work in tester even with your suggested modifications.


Regards, Mighty

 
Mighty7:

Hello,

very nice work. Thank you.

Can you please check the CanvasBar Sample? It won't work in tester even with your suggested modifications.

Regards, Mighty

Try moving ChartChanged before CopyRates

 
Thank you for the fast reply, but it's still not working.
 
Mighty7:
Thank you for the fast reply, but it's still not working.

This is because the call comes from OnChartEvent, which is not working properly in the tester.

Try this.

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[])
  {
   if(rates_total==prev_calculated)
     {
      Bar0.close=close[rates_total-1];Bar0.open=open[rates_total-1]; Bar0.high=high[rates_total-1];Bar0.low=low[rates_total-1];
      ShowBars(false);
     }
   else if (Canvas.tester) ShowBars();
   return(rates_total);
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id==CHARTEVENT_CHART_CHANGE) ShowBars(true);
  }
In the future, please attach a code or link. After all, I don't remember the name of my code, which I wrote almost 2 years ago.
Files:
CanvasBar.mq5  7 kb
 

"In the future, please attach a code or link. After all, I don't remember the name of my code, which I wrote almost 2 years ago."

Ok, I'll do. Now it is working (I had to remove the GetTickCount lines to get it synced). Thank you.