#property copyright "BLUR71"
#property link      ""
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 LimeGreen
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2
#property indicator_color3 DarkSlateGray
#property indicator_width3 1
#property indicator_color4 Aqua
#property indicator_width4 0
#property indicator_style4 2
#property indicator_levelcolor DarkSlateGray
#property indicator_levelstyle 2
#define   indicator_minimum -50
#define   indicator_maximum  50
extern bool AlertOn=false, ColorDescendingBars=false,PlotMainLine=true, PlotSignalLine=false;
extern int  RSIPeriod=13,RSIPrice=0,MASignal=0,MAMode=0,BuyAlertLevel=-10,SellAlertLevel=10;
extern double RSIHistoModify=1.5;
double UpBuffer[], DownBuffer[], RSIMain[], RSISignal[];
int Positive=0, Negative=0;
//----
int init()
  {IndicatorBuffers(4);
   SetIndexStyle(0,2);
   SetIndexBuffer(0,UpBuffer);
   SetIndexStyle(1,2);
   SetIndexBuffer(1,DownBuffer);
   if(PlotMainLine)
   SetIndexStyle(2,0); else
   SetIndexStyle(2,12);
   SetIndexBuffer(2,RSIMain);
   if (PlotSignalLine)
   SetIndexStyle(3,0); else
   SetIndexStyle(3,12);
   SetIndexBuffer(3,RSISignal);
   SetLevelValue(0,BuyAlertLevel);
   SetLevelValue(1,SellAlertLevel);
   return(0);}
//----
int deinit() {return(0);}
//----
int start()
{int counted_bars=IndicatorCounted(),I,limit;
 IndicatorShortName("RSI HistoAlert ["+RSIPeriod+","+RSIPrice+","+MASignal+
                    ","+MAMode+","+DoubleToStr(RSIHistoModify,2)+"X]");
 if (counted_bars<0) return(-1);
 if (counted_bars>0) counted_bars--;
 limit=Bars-31;
 if(counted_bars>=31) limit=Bars-counted_bars-1;
//----
   for (I=limit;I>=0;I--)
   {
         RSIMain[I]=((iRSI(NULL,0,RSIPeriod,RSIPrice,I)-50)*RSIHistoModify);
         if(RSIMain[I]>BuyAlertLevel)
         {
            if (Positive==0)
            {
               Positive=1;
               Negative=0;
               if (I == 1 && AlertOn ) Alert(Symbol()," M",Period()," RSI Histo BUY @ ",Ask);
             }
         }
         else if (RSIMain[I]<SellAlertLevel)
         {
            if(Negative==0)
            {
               Negative=1;
               Positive=0;
               if (I == 1 && AlertOn) Alert(Symbol()," M",Period()," RSI Histo SELL @ ",Ask);
            }
         }
         if(ColorDescendingBars==true)
         {
            if (RSIMain[I]>RSIMain[I+1])
            {
               UpBuffer[I]  =RSIMain[I];
               DownBuffer[I]=EMPTY_VALUE;
            }
            else
            {
               DownBuffer[I]=RSIMain[I];
               UpBuffer[I]=EMPTY_VALUE;
            }
         }
         else if(ColorDescendingBars==false && RSIMain[I]>=0.00)
            {
               UpBuffer[I]=RSIMain[I];
            }
         else 
         {DownBuffer[I]=RSIMain[I];}
   }
   for(I=0; I<limit; I++)RSISignal[I]=iMAOnArray(RSIMain,0,MASignal,0,MAMode,I);
return(0);
}