How to get the width and height of the Chart Window

 

Hi.

I would like to ask if you know how to get the width and height of a char window because i want to create EA objects that programmatically adjust to the windows height and width...


Thanks...

 
void     GetChartLimits(int&iLeft, int&iRight, double&top, double&bot,int iW=0){
   top      = WindowPriceMax(iW);   iLeft    = WindowFirstVisibleBar();
   bot      = WindowPriceMin(iW);   iRight   = iLeft-WindowBarsPerChart();
   if(top-bot < pips2dbl)  top    = bot+pips2dbl;     // Avoid scroll bug / div0
   if(iRight < 0)          iRight = 0;                // Chart is shifted.
}  // GetChartLimits
 
long height = ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);
long width = ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
 

Another solution to the problem is to use the OBJPROP_CORNER and set the 0,0 to the top right corner. This allows you to put text objects on the far right of the window aligned with the edge of the chart. 


   ObjectSet(obj_label,OBJPROP_CORNER,CORNER_RIGHT_UPPER);


 
Ian Venner:

I am trying to use your method but I get this warning: "possible loss of data due to type conversion DW-Panel v2.0.mq4 218 17"

The code runs successfully but I would like to get rid of the warning. Any thoughts?


/....... at beginning of code

#property indicator_chart_window

int extern atrPeriod = 14;
int extern width = 325;
int extern height = 25;
extern double maxSpread = 2.0;

//........ Later in "int OnCalculate(......){.......}"

int heightScreen=ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);
int widthScreen=ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);

height1 = heightScreen - height;
margin = widthScreen - width;
Documentation on MQL5: Language Basics / Data Types / Typecasting
Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Often a necessity occurs to convert one numeric type into another. Not all numeric types can be converted into another. Here is the scheme of allowed casting: Solid lines with arrows indicate changes that are performed almost without any loss of information. Instead of the char type, the bool type can be used (both take 1 byte of memory...
 
CaptainPablo:

I am trying to use your method but I get this warning: "possible loss of data due to type conversion DW-Panel v2.0.mq4 218 17"

The code runs successfully but I would like to get rid of the warning. Any thoughts?


I changed int to bool and it's all unicorns and rainbows now. Thanks.

 
CaptainPablo #:

I am trying to use your method but I get this warning: "possible loss of data due to type conversion DW-Panel v2.0.mq4 218 17"

The code runs successfully but I would like to get rid of the warning. Any thoughts?


(int) ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS); Please use conversion like this, it should resolve the warning.