//+------------------------------------------------------------------+
//|                                              Universal Pivot.mq4 |
//|                               Copyright © 2004, Poul_Trade_Forum |
//|                                                         Aborigen |
//|                                          http://forex.kbpauk.ru/ |
//+------------------------------------------------------------------+
#property copyright "Poul Trade Forum"
#property link      "http://forex.kbpauk.ru/"
//----
#property indicator_chart_window
//#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red

extern int period = 240;

double PBuffer[];
string Pv, Pivot, txtPivot;

double P;
double x;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
     
//---- TODO: add your code here
   ObjectDelete(Pivot);
   ObjectDelete(txtPivot);

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
     string short_name;
   SetIndexStyle(0,DRAW_LINE,0,2,Red);
   SetIndexBuffer(0,PBuffer);
   short_name="Filter H4";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexDrawBegin(0,1);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
      if (Period() > period) return(-1);
   int    dayi, counted_bars=IndicatorCounted();
   int limit, i;
//---- indicator calculation
   if (counted_bars <0) return(-1);
   limit=(Bars-counted_bars)-1;
//----   
   for(i=limit; i>=0;i--)
     {
      dayi = iBarShift(Symbol(), period, Time[i], false);
      P = (iHigh(Symbol(), period, dayi + 1) + iLow(Symbol(), period, dayi + 1) + iClose(Symbol(), period, dayi + 1)) / 3; 
      Pv = "Pivot";
      Pivot = "Pivot";
      txtPivot = "txtPivot";
      PBuffer[i]=P;
      SetPrice("Pivot", Time[i], P, indicator_color1);
      SetText("txtPivot", Pv, Time[i], P, indicator_color1);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetPrice(string name, datetime Tm, double Prc, color clr)
  {
   if(ObjectFind(name) == -1)
     {
       ObjectCreate(name, OBJ_ARROW, 0, Tm, Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, 1);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     }
   else
     {
       ObjectSet(name, OBJPROP_TIME1, Tm);
       ObjectSet(name, OBJPROP_PRICE1, Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, 1);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     } 
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetText(string name, string txt, datetime Tm, double Prc, color clr)
  {
   if(ObjectFind(name) == -1)
     {
       ObjectCreate(name, OBJ_TEXT, 0, Tm, Prc);
       ObjectSetText(name, txt, 10, "Times New Roman", clr);
       ObjectSet(name, OBJPROP_CORNER, 2);
     }
   else
     {
       ObjectSet(name, OBJPROP_TIME1, Tm);
       ObjectSet(name, OBJPROP_PRICE1, Prc);
       ObjectSetText(name, txt, 10, "Times New Roman", clr);
       ObjectSet(name, OBJPROP_CORNER, 2);
     } 
  }
//+------------------------------------------------------------------+