//+------------------------------------------------------------------+
//|                                         Динамический Pivot       |
//|                                         лёксус - Conversion only |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 White
//---- input parameters
extern int Formula=0;

//---- buffers
double Pivot[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  SetIndexBuffer(0,Pivot);
  SetIndexStyle (0,DRAW_SECTION);
	SetIndexEmptyValue(0,0.0);

  return(0);
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
int start()
{
// Строим Pivot и Res/Supp по FibonacciTrader Journal Issue 6 
  int i,shift;
  double FP,FH,FL;

//  if(Period()>60) return(0);

  for(shift=Bars-1; shift>=0; shift--)
  {
    Pivot[shift]=0;
    if (TimeHour(Time[shift])==0 && TimeMinute(Time[shift])==0 ) //начало дня 
  	{ 
      i=1; 
		  while(TimeDay(Time[shift+i])==TimeDay(Time[shift+i+1])) { i++; }

  		FH=High[Highest(NULL,0,MODE_HIGH,i,shift)];
      FL= Low[ Lowest(NULL,0,MODE_LOW, i,shift)];

  		FP=(FH+FL+Close[shift+1+Formula]+Close[shift+1+Formula])/4; //Значение PivotPoint 
  		Pivot[shift]=FP;
    }

  	if(shift==0)
  	{ 
  		i=1; 
  		while(TimeDay(Time[0])==TimeDay(Time[i])) { i++; }

  		FH=High[ Highest(NULL,0,MODE_HIGH,i,i)];
  		FL=Low[ Lowest(NULL,0,MODE_LOW,i,i)]; 

  		FP=(FH+FL+Close[0]+Close[0])/4; //Значение PivotPoint 
  		Pivot[0]=FP; 
  	} 
  }

  return(0);
}
//+------------------------------------------------------------------+