//+-------------------------------------------------------------------
//|
//| as described in Marh 2009 SFO magazine
//|
//| article : Trading FX Like Jesse Livermore Traded Stocks,
//| article by : Jamie Saettele
//|
//+-------------------------------------------------------------------
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2

//
//
//
//
//

extern int LookBackLength = 200;
extern int AtrLength      = 1;

//
//
//
//
//

double highValue[];
double lowValue[];
double atrValues[];

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//

int init()
{
   IndicatorBuffers(3);
      SetIndexBuffer(0,highValue); SetIndexStyle(0,DRAW_HISTOGRAM);
      SetIndexBuffer(1,lowValue);  SetIndexStyle(1,DRAW_HISTOGRAM);
      SetIndexBuffer(2,atrValues);
   IndicatorShortName("Pivotal points ("+LookBackLength+","+AtrLength+")");
   return(0);
}

//
//
//
//
//

int deinit() { return (0); }

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int i,limit,counted_bars=IndicatorCounted();

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit  = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //

   for(i=limit; i>=0; i--)
   {
      atrValues[i] = iATR(NULL,0,AtrLength,i);
         if (ArrayMaximum(atrValues,LookBackLength,i)==i)
         {
            highValue[i] = High[i];
            lowValue[i]  = Low[i];
         }
         else
         {
            highValue[i] = EMPTY_VALUE;
            lowValue[i]  = EMPTY_VALUE;
         }
   }     
   return(0);
}