//----
#property indicator_separate_window
#property indicator_buffers 3
//----
#property indicator_color1 LimeGreen
#property indicator_color2 LimeGreen
#property indicator_color3 LimeGreen
#property indicator_width1 1
#property indicator_width2 1
#property indicator_style2 2
//---- user changeable stuff
extern int FastEMA=36;
extern int SlowEMA=58;
extern int SignalEMA=9;
extern int MinMaxSearch=1;
extern int PipsFilter=30;
extern int FixedSpread=0;
//---- two buffers
double     PPOBuffer[];
double     SignalBuffer[];
double     lhBuffer[];
//---- misc
int nArrow = -1;

bool DrawDotAtPrice(datetime dt, double pr, string strObj, int _color)
{
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,SignalEMA);
   IndicatorDigits(Digits+1);
   SetIndexBuffer(0,PPOBuffer);
   SetIndexBuffer(1,SignalBuffer);
//----
   IndicatorShortName("Mash Potato Indicator ("+FastEMA+","+SlowEMA+","+SignalEMA+")");
   SetIndexLabel(0,"PPO");
   SetIndexLabel(1,"Signal");
//----
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,159);
   SetIndexBuffer(2,lhBuffer);
   SetIndexLabel(2,"LH");
//----
   nArrow = -1;
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   int cObj = ObjectsTotal();
   for (int i = cObj; i > 0; i--)
   { 
       string strObj = ObjectName(i - 1);
       if (StringFind(strObj, "zPPOhl_") != -1)
           ObjectDelete(strObj);
   }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   int Spread = MarketInfo(Symbol(), MODE_SPREAD);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- (FastEMA-SlowEMA)/SlowEMA
//---- PPO counted in the 1st buffer
   for(int i=0; i<limit; i++)
      PPOBuffer[i]=(iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i))/
      iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2nd buffer
   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(PPOBuffer,Bars,SignalEMA,0,MODE_EMA,i);
//---- find lows & highs
   for (i=1; i<limit; i++)
   {
       int iPrice;
       double dPrice;

       /* process only if no processed already! */
       if (lhBuffer[i + 2] != lhBuffer[0])
           continue;
       
       if (PPOBuffer[i + 2] > PPOBuffer[i + 1] &&
           PPOBuffer[i + 2] > PPOBuffer[i + 0] &&
           PPOBuffer[i + 2] >= PPOBuffer[i + 3] &&
           PPOBuffer[i + 2] >= PPOBuffer[i + 4] &&
           PPOBuffer[i + 2] > SignalBuffer[i + 2])
       {
           /* high */
           nArrow++;
           lhBuffer[i + 2] = PPOBuffer[i + 2] + 0.0001;
           iPrice = ArrayMaximum(High, MinMaxSearch + 1, i + 1);
           dPrice = High[iPrice] + (PipsFilter * Point);
           if (FixedSpread > 0)
               dPrice += (FixedSpread * Point);
           else
               dPrice += (Spread * Point);
           dPrice = NormalizeDouble(dPrice, Digits);
           DrawDotAtPrice(Time[iPrice],
                          dPrice,
                          "zPPOhl_" + DoubleToStr(nArrow, 0) + "_" + DoubleToStr(dPrice, Digits),
                          DeepPink);
       }
       else
       if (PPOBuffer[i + 2] < PPOBuffer[i + 1] &&
           PPOBuffer[i + 2] < PPOBuffer[i + 0] &&
           PPOBuffer[i + 2] <= PPOBuffer[i + 3] &&
           PPOBuffer[i + 2] <= PPOBuffer[i + 4] &&
           PPOBuffer[i + 2] < SignalBuffer[i + 2])
       {
           /* low */
           nArrow++;
           lhBuffer[i + 2] = PPOBuffer[i + 2] - 0.0001;
           iPrice = ArrayMinimum(Low, MinMaxSearch + 1, i + 1);
           dPrice = Low[iPrice] - (PipsFilter * Point);
           dPrice = NormalizeDouble(dPrice, Digits);
           DrawDotAtPrice(Time[iPrice],
                          dPrice,
                          "zPPOhl_" + DoubleToStr(nArrow, 0) + "_" + DoubleToStr(dPrice, Digits),
                          RoyalBlue);
       }
   }
   return(0);
  }
//+------------------------------------------------------------------+