//+-------------------------------------------------------------+
//| INDICATOR for 'Blended Pin Bars'         BlendedPinBars.mq4 |
//| copy to [experts\indicators] and recompile                  |
//+-------------------------------------------------------------+
#property copyright "Copyright © 2010 Robert Dee"

#define INDICATOR_VERSION    20100929
#define INDICATOR_NAME       "BlendedPinBars"
#define HOUR                 3600

#property indicator_chart_window
#property indicator_buffers 2

#property indicator_color1 LightSkyBlue    // LowerWick painted wick colour
#property indicator_color2 LightSalmon     // UpperWick painted wick colour

#property indicator_width1 1
#property indicator_width2 1

// persistent variables
double LowerWick[];
double UpperWick[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
// LowerWick style
   SetIndexStyle(0,DRAW_HISTOGRAM);
// UpperWick style
   SetIndexStyle(1,DRAW_HISTOGRAM);
// setup indicator buffers
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
   SetIndexBuffer(0,LowerWick);
   SetIndexBuffer(1,UpperWick);
// names for DataWindow and indicator subwindow label
   IndicatorDigits(Digits);
   IndicatorShortName(INDICATOR_NAME);
   SetIndexLabel(0,"");
   SetIndexLabel(1,"");
return(0);
}

//+------------------------------------------------------------------+
//| Indicator start() function called every time price changes (tic)
//+------------------------------------------------------------------+
int start()
{
int shift = Bars-1;
while(shift >= 0)
   {
   // PIN BARS ON HIGHER TIMEFRAME
   double rrHigh = MathMax(High[shift],High[shift+1]);
   double rrLow = MathMin(Low[shift],Low[shift+1]);
   double rrMid = (rrHigh + rrLow) / 2;
   
   // FORCE REDRAWS
   LowerWick[shift] = 0;
   UpperWick[shift] = 0;
   
   // BEARISH HIGHER TIMEFRAME WICKS
   if(Open[shift+1] < rrMid)          // prev candle opens below the middle of the range
   if(Close[shift] < rrMid)           // this candle closes below the middle of the range
      {LowerWick[shift] = MathMax(Open[shift+1],Close[shift])+4*Point; UpperWick[shift] = rrHigh;}

   // BULLISH HIGHER TIMEFRAME WICKS
   if(Open[shift+1] > rrMid)          // prev candle opens below the middle of the range
   if(Close[shift] > rrMid)           // this candle closes below the middle of the range
      {LowerWick[shift] = MathMin(Open[shift+1],Close[shift])-3*Point; UpperWick[shift] = rrLow;}

   shift--; // move forward one bar
   }

} // end of start()

//+------------------------------------------------------------------+
void deinit()
{
int i = 0;
while(i < Bars)
   {
   LowerWick[i] = 0; // cleanup display buffers
   UpperWick[i] = 0;
   i++;
   }
}