Libraries: Easy Canvas (iCanvas) - page 2

 
Nikolai Semko #:

Hello Luca, try this version 1.46.
If the problem persists, please post the bugs here again.

Thank you for the fast update.

The problem persists but it is related to a different issue, not to your code.

The problem is that in MQL4 I cannot add an indicator programmatically because the command ChartindicatorAdd exists only in MQL5. I can use iCustom but it is useful only to acquire data from the calculation array/buffer inside the indicator.

Probably your iCanvas works flawlessy with MQL5, I cannot test it.

(ref: https://www.mql5.com/en/forum/36119)


By the way thank you for the support!


Luca
Chart Event not working when the indicator using Chart Event is called from EA using iCustom function
Chart Event not working when the indicator using Chart Event is called from EA using iCustom function
  • 2014.09.11
  • www.mql5.com
Hello People In my recent project, I tried to call an indicator, which uses chart event and button objects, from EA using iCustom function...
 
giuliani luca #:

Thank you for the fast update.

The problem persists but it is related to a different issue, not to your code.

The problem is that in MQL4 I cannot add an indicator programmatically because the command ChartindicatorAdd exists only in MQL5. I can use iCustom but it is useful only to acquire data from the calculation array/buffer inside the indicator.

Probably your iCanvas works flawlessy with MQL5, I cannot test it.

(ref: https://www.mql5.com/en/forum/36119)


By the way thank you for the support!


Luca
I am a supporter of not using iCustom in EA, but using the calculated part of the required indicator inside EA.  Canvas just allows you to display all the necessary graphics without buffer arrays.  The advantages of this approach far outweigh the disadvantages.  Performance, manageability, control, visualization capabilities will be higher than through iCustom.
 
Last version 1.53
Files:
iCanvas.mqh  71 kb
 
Thanks @Nikolai Semko this is great. Easy replacement for many things.  Interestingly, the colours don't match the helper in vscode. The blue/red channels are swapped. So to get red on the canvas, vscode shows purple. 
 
Rob Perrett #:
Thanks @Nikolai Semko this is great. Easy replacement for many things.  Interestingly, the colours don't match the helper in vscode. The blue/red channels are swapped. So to get red on the canvas, vscode shows purple. 

This is really strange and this difference exists for two color modes COLOR_FORMAT_ARGB_NORMALIZE and COLOR_FORMAT_XRGB_NOALPHA.
Therefore, I prefer to use the HEX format without the ColorToARGB() function.

Very clear and understandable. Each color R, G, B can take values from 00 to FF (0 to 256)

The first byte is the alpha channel, responsible for transparency.

  • 0 - absolutely transparent
  • FF(256) - absolutely opaque
  • 80(128) - translucent.


 
@Nikolay7ko Is there a secret to make the canvas visible in the tester? Works fine live, but inside the visual tester I don't see it at all.
 
Rob Perrett #:
@Nikolay7ko Is there a secret to make the canvas visible in the tester? Works fine live, but inside the visual tester I don't see it at all.

https://www.mql5.com/en/forum/412168/page63#comment_37046782

Canvas is cool! - How do you measure the Z-axis behaviour in 3DSpiral?
Canvas is cool! - How do you measure the Z-axis behaviour in 3DSpiral?
  • 2020.01.25
  • www.mql5.com
What could the z-axis behaviour mean. ) but when viewed in space, it turns out to be a distance along the z-axis. In this case, all three dimensions have different magnitudes: x - time. There's also a 3d canvas with vector matrices
 
Rob Perrett # :
@Nikolay7ko Is there a secret to make the canvas visible in the tester? Works fine live, but inside the visual tester I don't see it at all.

Forum on trading, automated trading systems and testing trading strategies

Libraries: Easy Canvas

Nikolai Semko , 2020.11.10 22:51

 #property indicator_chart_window
#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/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,         // идентификатор события
                   const long & lparam,   // параметр события типа long
                   const double & dparam, // параметр события типа double
                   const string & sparam) { // параметр события типа 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;
}
//+------------------------------------------------------------------+

Highlighted in yellow is what is necessary to reduce the load on the tester
Highlighted in green is what is necessary for the correct drawing of coordinates. Try removing this line and see what happens in the tester.

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


But, unfortunately, in the Tester, the mouse movement event is processed only when the left mouse button is pressed.
This applies not only to my iCanvas class, but to any graphical output in the tester.
It’s just easier for me to implement this.
And even the GUI controls work quite normally:



 

@Nikolai Semko Thanks for the quick reply. It appears that iCanvas isn't returning the correct X and Y values when run inside the tester. I had a look at your code but didn't see anything obvious and didn't go too deep. Any thoughts?


Here is my code:

datetime startTime = rates[iLeft].time;
datetime endTime = rates[iRight].time + PeriodSeconds() * RectangleWidth;

double rectTop = isBullishFVG ? fillVal : rates[iLeft].low;
double rectBottom = isBullishFVG ? rates[iLeft].high : fillVal;
uint currentColor = isBullishFVG ? RectColorUp : RectColorDown;

Print("Add rect to canvas: ",startTime," ",rectBottom," ",endTime," ",rectTop);
Print("Returned coords from iCanvas: ",Canvas.X(startTime)," ",Canvas.Y(rectTop)," ",Canvas.X(endTime)," ",Canvas.Y(rectBottom));
Canvas.FillRectangle((int)(Canvas.X(startTime)),(int)(Canvas.Y(rectBottom)),(int)(Canvas.X(endTime)),(int)(Canvas.Y(rectTop)),currentColor);


canvas-tester-log

 
Rob Perrett #:

@Nikolai Semko Thanks for the quick reply. It appears that iCanvas isn't returning the correct X and Y values when run inside the tester. I had a look at your code but didn't see anything obvious and didn't go too deep. Any thoughts?


Here is my code:


In the previous post this was highlighted in green.

if (Canvas.tester) ChartChanged();
https://www.mql5.com/ru/forum/364640/page12#comment_21303258