WindowsPriceMax problem

 

here we have a problem, i have writen an example, uses WindowsPrixeMax in an indicator, and the call to function return the value of previus Period selected from Toolbox once one tick arrive.

there is no big problem, only wait to a next tick to the indicator's chart, update with correct data.

Here is the code

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("Top");
   ObjectDelete("Bottom");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   double Top=WindowPriceMax(0);
   double Bottom=WindowPriceMin(0);
   Print("Top=",Top,"Bot=",Bottom);
   double newTop,newBottom;
   double result;

   //Fresh Start
   ObjectDelete("Top");
   ObjectDelete("Bottom");

   newTop=Bottom+(Top-Bottom)*0.95;
   newBottom=Bottom+(Top-Bottom)*0.05;
   
   ObjectCreate("Top",OBJ_TREND,0,Time[50], newTop , Time[0], newTop );
   ObjectSet("Top",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSet("Top",OBJPROP_WIDTH,4 );
   ObjectSet("Top",OBJPROP_RAY,false);
   ObjectSet("Top",OBJPROP_COLOR, Red);
   
   ObjectCreate("Bottom",OBJ_TREND,0,Time[50], newBottom , Time[0], newBottom );
   ObjectSet("Bottom",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSet("Bottom",OBJPROP_WIDTH,4 );
   ObjectSet("Bottom",OBJPROP_RAY,false);
   ObjectSet("Bottom",OBJPROP_COLOR, Red);
   
   Comment("Period:",Period(),"\nTop:",newTop,"\nBottom:",newBottom);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

There is the problem

first: the indicator shows normal, like must be. once droped into chart M1.

Fist Image Shows Normal in M1

Once press the toolbox button to change chart's period, to M5 this happends:

Indicator shows ignoring the new period.

AS YOU CAN SEE, THE INDICATOR GETS THE WINDOWSMAXPRICE THE SAME OF THE M1. ( THIS IS BAD ).

*** NOTE THIS: THE NEW PERIOD IS PRINTED 1 TO 5, indicating the start() function in the indicator was executed.

And, ONE TICK ARRIVES TO CHART. THIS HAPPENDS:

After Tick

AFTER THE FIRS TICK ARRIVES TO CHART, all BACK TO NORMAL.

How can get the new value of WindowsPriceMax and WindowsPriceMin, instantantly after Button M1,M5,M15,M30,H1,H4, was pressed in user interface?