WindowPriceMax()/WindowPriceMin() problem

 

Guys,

Very simply drawing a rectangle full height of chart. WindowPriceMax()/WindowPriceMin() do not change values when timeframe is changed.

int init()
  {
   ObjectCreate("rect",OBJ_RECTANGLE,0,Time[30],WindowPriceMax(0),Time[50],WindowPriceMin(0));
   ObjectSet("rect",OBJPROP_COLOR,Red);
   WindowRedraw();
   return(0);
  }

 If this code is compiled with indicator on M5 timeframe then when I change to a higher timeframe, say D1 the rectangle keeps the WindowPriceMax/Min values from the M5 timeframe!! So the rectangle does not draw the full height of the higher timeframe.

Any ideas? (I must be doing something incredibly stupid!)

 
sd59:
WindowPriceMax()/WindowPriceMin() do not change values when timeframe is changed.
Any ideas? (I must be doing something incredibly stupid!)

Wrong. You would know that had you bothered to print the values, instead of assumeing.

Yes you are. You create the rectangle the first time. When you change timeframes, the ObjectCreate FAILS as the object already exists. You would know this had you checked: What are Function return values ? How do I use them ? - MQL4 forum

either

  1. remove objects you create in deinit
  2. remove object and then try to create
  3. or test if the object exists and create or modify
 
WHRoeder:

Wrong. You would know that had you bothered to print the values, instead of assumeing.

Yes you are. You create the rectangle the first time. When you change timeframes, the ObjectCreate FAILS as the object already exists. You would know this had you checked: What are Function return values ? How do I use them ? - MQL4 forum

either

  1. remove objects you create in deinit
  2. remove object and then try to create
  3. or test if the object exists and create or modify

 can do without the sarcastic comments!

already did it....i didn't put all code in - this is full code...what now!??

int init()
  {
   ObjectCreate("rect",OBJ_RECTANGLE,0,Time[200],WindowPriceMax(0),Time[170],WindowPriceMin(0));
   ObjectSet("rect",OBJPROP_COLOR,Red);
   windowRedraw();
  }

int deinit()
  {
   ObjectDelete("rect");
   return(0);
  }
 
sd59:

 can do without the sarcastic comments!

already did it....i didn't put all code in - this is full code...what now!??

Try the search,  you will find that there is at least one other problem with WindowPriceMax and min
 
RaptorUK:
Try the search,  you will find that there is at least one other problem with WindowPriceMax and min


I did the search and none are directly related to my problem. One was about minimising MT4 which is not what i am doing. 

The rectangle draws fine on the first chart it is loaded on. The issue is that WindowMax()/WindowMin() functions do not update they keep the last value. So if i have full height rectangles on M5 chart when i change to MN chart the rectangles are much smaller because of vertical scale differences between the two timeframes.

The documentation says:

double WindowPriceMax(int index=0)

Returns maximal value of the vertical scale of the specified subwindow of the current chart (0-main chart window, the indicators' subwindows are numbered starting from 1). If the subwindow index has not been specified, the maximal value of the price scale of the main chart window is returned.

It doesn't seem to do what it says on the tin! 

This seems like a bug to me or am i missing something? 

 
sd59:


I did the search and none are directly related to my problem. One was about minimising MT4 which is not what i am doing. 

The rectangle draws fine on the first chart it is loaded on. The issue is that WindowMax()/WindowMin() functions do not update they keep the last value. So if i have full height rectangles on M5 chart when i change to MN chart the rectangles are much smaller because of vertical scale differences between the two timeframes.

The documentation says:

double WindowPriceMax(int index=0)

Returns maximal value of the vertical scale of the specified subwindow of the current chart (0-main chart window, the indicators' subwindows are numbered starting from 1). If the subwindow index has not been specified, the maximal value of the price scale of the main chart window is returned.

It doesn't seem to do what it says on the tin! 

This seems like a bug to me or am i missing something? 

Post an Indicator sample that demonstrates the issue so that it can be reproduced, when I have reproduced your issue I will report it to the Service Desk.

You may want to move your code from init() to start(),  or at least adding an update to the rectangle position in start(),  WindowMax() & Min may need a tick or 2 to get the correct values for the new timeframe, consider that the new timeframe may be missing some recent data,  that data needs to be downloaded first before WindowMax() & Min are correct. 

 

OK, OK - I finally got it. All a bit quirky but if I 'fix' the scale in chart properties the rectangles are drawn full height across all timeframes.

Maximal value as described above is not necessarily the 'observed' maximum (or minimum) price on the chart.

 
sd59:

OK, OK - I finally got it. All a bit quirky but if I 'fix' the scale in chart properties the rectangles are drawn full height across all timeframes.

Maximal value as described above is not necessarily the 'observed' maximum (or minimum) price on the chart.

I'm pretty certain it is.
 

Just for completeness this is what happens with this code: changing timeframe from M5 to D1.

int init()
  {
   ObjectCreate("lane1",OBJ_RECTANGLE,0,Time[200],WindowPriceMax(0),Time[170],WindowPriceMin(0));
   ObjectSet("lane1",OBJPROP_COLOR,Red);
   Print(WindowPriceMax(0),"  ",WindowPriceMin(0));
   
   ObjectCreate("lane2",OBJ_RECTANGLE,0,Time[168],WindowPriceMax(0),Time[138],WindowPriceMin(0));
   ObjectSet("lane2",OBJPROP_COLOR,Red);
   
   ObjectCreate("lane3",OBJ_RECTANGLE,0,Time[136],WindowPriceMax(0),Time[106],WindowPriceMin(0));
   ObjectSet("lane3",OBJPROP_COLOR,Red);
   
   ObjectCreate("lane4",OBJ_RECTANGLE,0,Time[104],WindowPriceMax(0),Time[74],WindowPriceMin(0));
   ObjectSet("lane4",OBJPROP_COLOR,Red);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("lane1");
   ObjectDelete("lane2");
   ObjectDelete("lane3");
   ObjectDelete("lane4");
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
   ObjectCreate("lane1",OBJ_RECTANGLE,0,Time[200],WindowPriceMax(0),Time[170],WindowPriceMin(0));
   ObjectSet("lane1",OBJPROP_COLOR,Red);
   Print(WindowPriceMax(0),"  ",WindowPriceMin(0));
   
   ObjectCreate("lane2",OBJ_RECTANGLE,0,Time[168],WindowPriceMax(0),Time[138],WindowPriceMin(0));
   ObjectSet("lane2",OBJPROP_COLOR,Red);
   
   ObjectCreate("lane3",OBJ_RECTANGLE,0,Time[136],WindowPriceMax(0),Time[106],WindowPriceMin(0));
   ObjectSet("lane3",OBJPROP_COLOR,Red);
   
   ObjectCreate("lane4",OBJ_RECTANGLE,0,Time[104],WindowPriceMax(0),Time[74],WindowPriceMin(0));
   ObjectSet("lane4",OBJPROP_COLOR,Red);
   return(0);
  }

 M5 imageD1 chart

 
sd59:

Just for completeness this is what happens with this code: changing timeframe from M5 to D1.

 

Your code is still wrong as you have already been told . . .

int init()
  {
   ObjectCreate("lane1",OBJ_RECTANGLE,0,Time[200],WindowPriceMax(0),Time[170],WindowPriceMin(0));
   ObjectSet("lane1",OBJPROP_COLOR,Red);
   Print(WindowPriceMax(0),"  ",WindowPriceMin(0));
   

  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
   ObjectCreate("lane1",OBJ_RECTANGLE,0,Time[200],WindowPriceMax(0),Time[170],WindowPriceMin(0));
   ObjectSet("lane1",OBJPROP_COLOR,Red);
   Print(WindowPriceMax(0),"  ",WindowPriceMin(0));

You create Object lane1 in init() and then again in start() . . and again in start() for each tick . . .  after the ObjectCreate() in start do this . . .

Print("start: Check for Error after ObjectCreate: ", GetLasteError());

 You will see error  . . .    ERR_OBJECT_ALREADY_EXISTS 4200 Object exists already.

 

Code works if you do it properly . . .

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
   if(ObjectFind("lane1") == -1)
      ObjectCreate("lane1",OBJ_RECTANGLE,0,Time[200],WindowPriceMax(0),Time[170],WindowPriceMin(0));
   else
      {
      ObjectSet("lane1", OBJPROP_TIME1, Time[200]);
      ObjectSet("lane1", OBJPROP_PRICE1, WindowPriceMax(0));
      ObjectSet("lane1", OBJPROP_TIME2, Time[170]);
      ObjectSet("lane1", OBJPROP_PRICE2, WindowPriceMin(0));
      }
   ObjectSet("lane1",OBJPROP_COLOR,Red);
   Print(WindowPriceMax(0),"  ",WindowPriceMin(0));
   
   if(ObjectFind("lane2") == -1)
      ObjectCreate("lane2",OBJ_RECTANGLE,0,Time[168],WindowPriceMax(0),Time[138],WindowPriceMin(0));
   else
      {
      ObjectSet("lane2", OBJPROP_TIME1, Time[168]);
      ObjectSet("lane2", OBJPROP_PRICE1, WindowPriceMax(0));
      ObjectSet("lane2", OBJPROP_TIME2, Time[138]);
      ObjectSet("lane2", OBJPROP_PRICE2, WindowPriceMin(0));
      }
   ObjectSet("lane2",OBJPROP_COLOR,Red);
   
   if(ObjectFind("lane3") == -1)
      ObjectCreate("lane3",OBJ_RECTANGLE,0,Time[136],WindowPriceMax(0),Time[106],WindowPriceMin(0));
   else
      {
      ObjectSet("lane3", OBJPROP_TIME1, Time[136]);
      ObjectSet("lane3", OBJPROP_PRICE1, WindowPriceMax(0));
      ObjectSet("lane3", OBJPROP_TIME2, Time[106]);
      ObjectSet("lane3", OBJPROP_PRICE2, WindowPriceMin(0));
      }
   ObjectSet("lane3",OBJPROP_COLOR,Red);
   
   if(ObjectFind("lane4") == -1)
      ObjectCreate("lane4",OBJ_RECTANGLE,0,Time[104],WindowPriceMax(0),Time[74],WindowPriceMin(0));
   else
      {
      ObjectSet("lane4", OBJPROP_TIME1, Time[104]);
      ObjectSet("lane4", OBJPROP_PRICE1, WindowPriceMax(0));
      ObjectSet("lane4", OBJPROP_TIME2, Time[74]);
      ObjectSet("lane4", OBJPROP_PRICE2, WindowPriceMin(0));
      }
   ObjectSet("lane4",OBJPROP_COLOR,Red);

   return(0);
  }
Reason: