//+------------------------------------------------------------------+
//|                                            TRO_Heatmap_Int       |
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|                                                                  |
//|   therumpledone@gmail.com                                        |  
//+------------------------------------------------------------------+ 

#property  copyright "Copyright © 2008, Avery T. Horton, Jr. aka TRO" 
#property  link      "http://www.therumpledone.com/" 

#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Red   
#property indicator_color2 Maroon        
#property indicator_color3 Orange     
#property indicator_color4 LightYellow  
#property indicator_color5 Yellow        
#property indicator_color6 Gold     
#property indicator_color7 Blue           
#property indicator_color8 Navy  
   
//---- parameters


extern string Ind_Name_1 ="iRSI";



extern double iParm3 = 2;
extern double iParm4 = 0;
extern double iParm5 = 0;
extern double iParm6 = 0;
extern double iParm7 = 0;
extern double iParm8 = 0;




extern double iLevel6 =  95 ;
extern double iLevel5 =  80 ;
extern double iLevel4 =  65 ;
extern double iLevel3 =  50 ;
extern double iLevel2 =  35 ;
extern double iLevel1 =  20 ;
extern double iLevel0 =  5 ;

   double cVal, pVal; 
 
//---- buffers
   double     ExtBuffer0[];   
   double     ExtBuffer1[];
   double     ExtBuffer2[];
   double     ExtBuffer3[]; 
   double     ExtBuffer4[];   
   double     ExtBuffer5[];
   double     ExtBuffer6[]; 
   double     ExtBuffer7[];
   double     ExtBuffer8[]; 
   
   string CurrencyPair ;
   
   int Periods ;

//+------------------------------------------------------------------+
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, indicator_color1);
   SetIndexStyle(1,DRAW_HISTOGRAM, EMPTY, 4, indicator_color2);
   SetIndexStyle(2,DRAW_HISTOGRAM, EMPTY, 4, indicator_color3);
   SetIndexStyle(3,DRAW_HISTOGRAM, EMPTY, 4, indicator_color4);
   SetIndexStyle(4,DRAW_HISTOGRAM, EMPTY, 4, indicator_color5);
   SetIndexStyle(5,DRAW_HISTOGRAM, EMPTY, 4, indicator_color6);
   SetIndexStyle(6,DRAW_HISTOGRAM, EMPTY, 4, indicator_color7);
   SetIndexStyle(7,DRAW_HISTOGRAM, EMPTY, 4, indicator_color8);
   
   for (int i=0;i<indicator_buffers;i++) SetIndexLabel(i,NULL);   
   Periods      = Period();
   CurrencyPair = Symbol();
   if (iClose(CurrencyPair,0,0) == 0)
              CurrencyPair = Symbol();
   IndicatorShortName(CurrencyPair+" "+ Ind_Name_1+ "("+iParm3+")");
   return(1);
}
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }

//+------------------------------------------------------------------+
int start()
  {
  
   int    counted_bars=IndicatorCounted();
   
   if (counted_bars<0) return(-1);
 
   if (counted_bars>0) counted_bars--;
   
   int    pos=Bars-counted_bars;

 
   while(pos>=0)
   {          
     
      DoWork(CurrencyPair,Periods,pos) ;            

      while(true)
      {
         if(cVal > iLevel6) { drawblock(4,0,0,0,0,0,0,0,pos); break  ; }
         if(cVal > iLevel5) { drawblock(0,4,0,0,0,0,0,0,pos); break  ; }
         if(cVal > iLevel4) { drawblock(0,0,4,0,0,0,0,0,pos); break  ; }         
         if(cVal > iLevel3) { drawblock(0,0,0,4,0,0,0,0,pos); break  ; }
         if(cVal > iLevel2) { drawblock(0,0,0,0,4,0,0,0,pos); break  ; }      
         if(cVal > iLevel1) { drawblock(0,0,0,0,0,4,0,0,pos); break  ; }        
         if(cVal > iLevel0) { drawblock(0,0,0,0,0,0,4,0,pos); break  ; }     
                              drawblock(0,0,0,0,0,0,0,4,pos); break  ;        
      }
      
     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;
}

  
//+------------------------------------------------------------------+

void DoWork( string myPair, int myPeriod , int p )  
{

double cX, pX ;

while(true)
{

if ( Ind_Name_1=="tMid"  ) { cVal = (iHigh(myPair, myPeriod, p ) + iLow(myPair, myPeriod, p ) ) * 0.5  ; 
                             pVal = (iHigh(myPair, myPeriod, p + 1 ) + iLow(myPair, myPeriod, p + 1 ) ) * 0.5  ;  break;}

if ( Ind_Name_1=="tPrMid"  ) { cVal = (iHigh(myPair, myPeriod, p + 1 ) + iLow(myPair, myPeriod, p + 1 ) ) * 0.5  ; 
                             pVal = (iHigh(myPair, myPeriod, 2 ) + iLow(myPair, myPeriod, 2 ) ) * 0.5  ;  break;}


if ( Ind_Name_1=="iOpen"  ) { cVal = iOpen(myPair, myPeriod, iParm3 ); pVal = iOpen(myPair, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iClose"  ) { cVal = iClose(myPair, myPeriod, iParm3 ); pVal = iClose(myPair, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iHigh"  ) { cVal = iHigh(myPair, myPeriod, iParm3 ); pVal = iHigh(myPair, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iLow"  )  { cVal = iLow(myPair, myPeriod, iParm3 );  pVal = iLow(myPair, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iHighest"  ) { cX = iHighest(myPair, myPeriod, iParm3, iParm4, iParm5 );    cVal = iHigh(myPair, myPeriod, cX ) ;
                                 pX = iHighest(myPair, myPeriod, iParm3, iParm4, iParm5+1 );  pVal = iHigh(myPair, myPeriod, pX );  break;}
                                 
if ( Ind_Name_1=="iLowest"  )  { cX = iLowest(myPair, myPeriod, iParm3, iParm4, iParm5);    cVal = iLow(myPair, myPeriod, cX ) ;
                                 pX = iLowest(myPair, myPeriod, iParm3, iParm4, iParm5+1 ); pVal = iLow(myPair, myPeriod, pX ) ; break;}



if ( Ind_Name_1=="iAC"  ) { cVal = iAC(myPair, myPeriod, p ); pVal = iAC(myPair, myPeriod, 1 ); break;}
                            
if ( Ind_Name_1=="iAD"  ) { cVal = iAD(myPair, myPeriod, p ); pVal = iAD(myPair, myPeriod, 1 ); break;}
 
if ( Ind_Name_1=="iADX" ) { cVal = iADX(myPair,myPeriod, iParm3, iParm4, iParm5, p ) ;  
                            pVal = iADX(myPair,myPeriod, iParm3, iParm4, iParm5, p + 1 ) ; break;}

if ( Ind_Name_1=="iATR" ) { cVal = iATR(myPair,myPeriod, iParm3,  p ) ;  
                            pVal = iATR(myPair,myPeriod, iParm3,  p + 1 ) ; break;} 
                            
if ( Ind_Name_1=="iAO" )  { cVal = iAO(myPair,myPeriod, p ) ;  
                            pVal = iAO(myPair,myPeriod,  p + 1 ) ; break;} 
                            
if ( Ind_Name_1=="iBearsPower" ) { cVal = iBearsPower(myPair,myPeriod, iParm3, iParm4,  p ) ;  
                                   pVal = iBearsPower(myPair,myPeriod, iParm3, iParm4,  p + 1 ) ; break;}  

if ( Ind_Name_1=="iBullsPower" ) { cVal = iBullsPower(myPair,myPeriod, iParm3, iParm4,  p ) ;  
                                   pVal = iBullsPower(myPair,myPeriod, iParm3, iParm4,  p + 1 ) ; break;}  

if ( Ind_Name_1=="iCCI" ) { cVal = iCCI(myPair,myPeriod, iParm3, iParm4,  p ) ;  
                            pVal = iCCI(myPair,myPeriod, iParm3, iParm4,  p + 1 ) ; break;}  

if ( Ind_Name_1=="iDeMarker" ) { cVal = iDeMarker(myPair,myPeriod, iParm3,  p ) ;  
                                 pVal = iDeMarker(myPair,myPeriod, iParm3,  p + 1 ) ; break;}  

if ( Ind_Name_1=="iRSI" ) { cVal = iRSI(myPair,myPeriod, iParm3, iParm4,  p ) ;  
                            pVal = iRSI(myPair,myPeriod, iParm3, iParm4,  p + 1 ) ; break;}  

if ( Ind_Name_1=="iForce" ) { cVal = iForce(myPair,myPeriod, iParm3, iParm4, iParm5, p ) ;  
                              pVal = iForce(myPair,myPeriod, iParm3, iParm4, iParm5, p + 1 ) ; break;}

if ( Ind_Name_1=="iFractals" ) { cVal = iFractals(myPair,myPeriod, iParm3,  p ) ;  
                                 pVal = iFractals(myPair,myPeriod, iParm3,  p + 1 ) ; break;} 

if ( Ind_Name_1=="iBWMFI" )  { cVal = iBWMFI(myPair,myPeriod, p ) ;  
                               pVal = iBWMFI(myPair,myPeriod,  p + 1 ) ; break;} 
                               
if ( Ind_Name_1=="iMomentum" ) { cVal = iMomentum(myPair,myPeriod, iParm3, iParm4,  p ) ;  
                                 pVal = iMomentum(myPair,myPeriod, iParm3, iParm4,  p + 1 ) ; break;}                                 
                               

if ( Ind_Name_1=="iMFI" ) { cVal = iMFI(myPair,myPeriod, iParm3,  p ) ;  
                            pVal = iMFI(myPair,myPeriod, iParm3,  p + 1 ) ; break;}                                
                               
if ( Ind_Name_1=="iMA" ) { cVal = iMA(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, p ) ;  
                           pVal = iMA(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, p + 1 ) ; break;}
                              
                              
if ( Ind_Name_1=="iOsMA" ) { cVal = iOsMA(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, p ) ;  
                             pVal = iOsMA(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, p + 1 ) ; break;}   
                             
                             
if ( Ind_Name_1=="iMACD" ) { cVal = iMACD(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, p ) ;  
                             pVal = iMACD(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, p + 1 ) ; break;}                               
                                                             

if ( Ind_Name_1=="iOBV" ) { cVal = iOBV(myPair,myPeriod, iParm3,  p ) ;  
                            pVal = iOBV(myPair,myPeriod, iParm3,  p + 1 ) ; break;} 


if ( Ind_Name_1=="iSAR" ) { cVal = iSAR(myPair,myPeriod, iParm3, iParm4,  p ) ;  
                            pVal = iSAR(myPair,myPeriod, iParm3, iParm4,  p + 1 ) ; break;} 

if ( Ind_Name_1=="iRVI" ) { cVal = iRVI(myPair,myPeriod, iParm3, iParm4,  p ) ;  
                            pVal = iRVI(myPair,myPeriod, iParm3, iParm4,  p + 1 ) ; break;} 
                             

if ( Ind_Name_1=="iStdDev" ) { cVal = iStdDev(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, p ) ;  
                               pVal = iStdDev(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, p + 1 ) ; break;} 
                                                              

if ( Ind_Name_1=="iStochastic" ) { cVal = iStochastic(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, iParm8, p ) ;  
                                   pVal = iStochastic(myPair,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, iParm8, p + 1 ) ; break;}                               
                                                             
if ( Ind_Name_1=="iWPR" ) { cVal = iWPR(myPair,myPeriod, iParm3,  p ) ;  
                            pVal = iWPR(myPair,myPeriod, iParm3,  p + 1 ) ; break;} 
                                
//IndHead = "ERROR! NO SUCH INDICATOR"; cVal = -999.99;  break;
}                                

}


//+------------------------------------------------------------------+
 /*                                                                                                                    
Comment(
Ind_Name_1, "\n",
"cVal = ", DoubleToStr(cVal,Digits), "\n",
myPair, "\n",
myPeriod, "\n",

"iParm3 = ", DoubleToStr(iParm3,Digits), "\n",


"") ;

*/
//+------------------------------------------------------------------+

