//+------------------------------------------------------------------+
//|                                                 mn nPeriodHL.mq4 |
//+------------------------------------------------------------------+
#property copyright "Mn"

#property indicator_chart_window

extern int mPeriods = 5, mTimeFrame = 1440;
extern color mCol1 = Red, mCol2 = Blue;

//+------------------------------------------------------------------+
int init()
  {
    ObjectCreate("nPerH", OBJ_TREND, 0, 0, 0, 0, 0);
    ObjectSet("nPerH", OBJPROP_COLOR, mCol2);
    ObjectSet("nPerH", OBJPROP_WIDTH, 2);
    ObjectSet("nPerH", OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet("nPerH", OBJPROP_RAY, false);

    ObjectCreate("nPerL", OBJ_TREND, 0, 0, 0, 0, 0);
    ObjectSet("nPerL", OBJPROP_COLOR, mCol1);
    ObjectSet("nPerL", OBJPROP_WIDTH, 2);
    ObjectSet("nPerL", OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet("nPerL", OBJPROP_RAY, false);

   return(0);
  }

//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("nPerH");
   ObjectDelete("nPerL");
   
   return(0);
  }

//+------------------------------------------------------------------+
int start()
  {
    int i, mShiftH, mShiftL, mTimeH, mTimeL, mBars = IndicatorCounted();
    double mHigh, mLow;
    bool  mUpAlert = false, mDownAlert = false;
    
   i = Bars - mBars - 1;
   while(i >= 0)
     {
       mShiftH = iHighest(NULL, mTimeFrame, MODE_HIGH, mPeriods, 0);
       mShiftL = iLowest(NULL, mTimeFrame, MODE_LOW, mPeriods, 0);
       mHigh = iHigh(NULL, mTimeFrame, mShiftH);
       mLow = iLow(NULL, mTimeFrame, mShiftL);
       mTimeH = iTime(NULL, mTimeFrame, mShiftH);
       mTimeL = iTime(NULL, mTimeFrame, mShiftL);
       
     ObjectSet("nPerH", OBJPROP_TIME1, mTimeH);
     ObjectSet("nPerH", OBJPROP_TIME2, Time[0]);
     ObjectSet("nPerH", OBJPROP_PRICE1, mHigh);
     ObjectSet("nPerH", OBJPROP_PRICE2, mHigh);
     ObjectSet("nPerL", OBJPROP_TIME1, mTimeL);
     ObjectSet("nPerL", OBJPROP_TIME2, Time[0]);
     ObjectSet("nPerL", OBJPROP_PRICE1, mLow);
     ObjectSet("nPerL", OBJPROP_PRICE2, mLow);
     i--;
    }
   if (Bid <= mLow && mUpAlert)
     {
      Alert(Symbol(), " Bounce or Breakout? - ", mLow);
      mUpAlert = true;
      mDownAlert = false;
     }

   if (Bid >= mHigh && mDownAlert)
     {
      Alert(Symbol(), " Bounce or Breakout? - ", mHigh);
      mUpAlert = false;
      mDownAlert = true;
     }
 
    
    
   return(0);
  }
//+------------------------------------------------------------------+