//+------------------------------------------------------------------+
//|                                                    PNell5MinMAvg |
//|                                                           Palmer |
//|                                              www.fxtradeblog.com |
//|                                              www.forexrhythm.com | 
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 C'162,208,162'
#property indicator_color2 C' 90,185, 90'// light green
#property indicator_color3 C' 23,139, 23'// dark green 
#property indicator_color4 C'192,192,192'// gray 
#property indicator_color5 C'255,255,0'//yellow
#property indicator_color6 C'255,115,115'//light red
#property indicator_color7 C'255, 76, 76' 
#property indicator_color8 C'255,32,32'//dark red



//---- buffers
   double     ExtBuffer0[];   
   double     ExtBuffer1[];
   double     ExtBuffer2[];
   double     ExtBuffer3[]; 
   double     ExtBuffer4[];   
   double     ExtBuffer5[];
   double     ExtBuffer6[]; 
   double     ExtBuffer7[];
   double     ExtBuffer8[]; 
    

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
   SetIndexBuffer(3,ExtBuffer3);
   SetIndexBuffer(4,ExtBuffer4);
   SetIndexBuffer(5,ExtBuffer5);
   SetIndexBuffer(6,ExtBuffer6);
   SetIndexBuffer(7,ExtBuffer7);
   
   SetIndexStyle(0,DRAW_HISTOGRAM, EMPTY, 4, C'162,208,162');
   SetIndexStyle(1,DRAW_HISTOGRAM, EMPTY, 4, C'90,185,90');//light green
   SetIndexStyle(2,DRAW_HISTOGRAM, EMPTY, 4, C'23,139,23'); //dark green
   SetIndexStyle(3,DRAW_HISTOGRAM, EMPTY, 4, C'192,192,192'); //gray
   SetIndexStyle(4,DRAW_HISTOGRAM, EMPTY, 4, C'255,255,0');//yellow
   SetIndexStyle(5,DRAW_HISTOGRAM, EMPTY, 4, C'255,115,115');//light red
   SetIndexStyle(6,DRAW_HISTOGRAM, EMPTY, 4, C'255,76,76');
   SetIndexStyle(7,DRAW_HISTOGRAM, EMPTY, 4, C'255,32,32'); //dark red
   
   for (int i=0;i<indicator_buffers;i++) SetIndexLabel(i,NULL);   


   IndicatorShortName("PNell5MinMavg");
   return(1);
}

int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int start()
  {
  
  
  
   int    counted_bars=IndicatorCounted();
   
//---- check for possible errors
   if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if (counted_bars>0) counted_bars--;
   
   int    pos=Bars-counted_bars;
 

   double aa;
   double bb;
   double cc;

   
  
//---- main calculation loop
   while(pos>=0)
     {   
    
         aa=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,pos);
         bb=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,pos);
         cc=iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,pos);
       
         
        
           //Moving Averages Are Bearish = Draw Dark Red Blocks
                  if (aa < bb && bb < cc && aa < cc)
                  {drawblock(0,0,0,0,0,0,0,5,pos);}
                          
          //Moving Averages Are Bullish = Draw Dark Green Blocks
                  if (aa > bb && bb > cc && aa > cc)
                  {drawblock(0,0,5,0,0,0,0,0,pos);}
          
          /////////////////////////////////////////////////////////////////
          //          Draw Yellow Blocks Within The War Zone             //
          //                                                             //
          //    I can't get this to work for some reason. The logic is   // 
          //    there but it paints previous bars. Take shot if you like //
          //                                                             //
          //                                                             //
          //  Price Is In The War Zone (Bear Trend) = Draw Yellow Blocks //
          //                                                             //                                                             //
          //   if(aa < bb && bb < cc && aa < cc && Bid >=aa && Bid <=bb) //
          //        {drawblock(0,0,0,0,5,0,0,0,pos);}                    //
          //                                                             //
          //  Price Is In The War Zone (Bull Trend) = Draw Yellow Blocks //   
          //                                                             // 
          //   if(aa > bb && bb > cc && aa > cc && Bid <=aa && Bid >==bb)//
          //        {drawblock(0,0,0,0,5,0,0,0,pos);}                    //
          //                                                             //
          /////////////////////////////////////////////////////////////////
          
          //Moving Averages Are Constricted = No Trend = Draw Gray Blocks     
                  if (aa > bb && bb < cc)
                  {drawblock(0,0,0,5,0,0,0,0,pos);}
            
                  if (aa < bb && bb > cc)
                  {drawblock(0,0,0,5,0,0,0,0,pos);}
      
           
         pos--;
     }
//----
   return(0);
  }
      
void drawblock(int a,int b,int c,int d,int e,int f,int g,int h,int pos)

{
         
               ExtBuffer0[pos]=a;    
               ExtBuffer1[pos]=b;
               ExtBuffer2[pos]=c;
               ExtBuffer3[pos]=d;
               ExtBuffer4[pos]=e;
               ExtBuffer5[pos]=f;
               ExtBuffer6[pos]=g;
               ExtBuffer7[pos]=h;
} 