CHART_PRICE_MIN giving sometimes zero

 

The following script works for Subwindow=0, not for Subwindow=1 (it will return both values as 0)

void OnStart()
  {
   double priceMin=ChartGetDouble(0,CHART_PRICE_MIN,1);
   double priceMax=ChartGetDouble(0,CHART_PRICE_MAX,1);
   Print("CHART_PRICE_MIN =",priceMin);
   Print("CHART_PRICE_MAX =",priceMax);
  }

Also, if the same code is put into EA, and even for Subwindow=0, it works only the first Run, but if i drag another currency to the chart, it gives also 0,0.

It this a bug?

I am trying to fit a custom made chart into a narrow subwindow...

 
Ziad El:

The following script works for Subwindow=0, not for Subwindow=1 (it will return both values as 0)

Also, if the same code is put into EA, and even for Subwindow=0, it works only the first Run, but if i drag another currency to the chart, it gives also 0,0.

It this a bug?

I am trying to fit a custom made chart into a narrow subwindow...


Yes it's a bug.

The workaround is to use the OnTimer event. first enable the timer for a second in OnInit, than put your code in the timer to read priceMin and priceMax and stop the timer.

I think MT5 runs the user code before initialization of  some internal chart properties which causes this problem. using a timer you can get the values after your programs first run. 

 
just to say '' WELCOME TO NEW YEAR 2019''
Reason: