//https://forex-station.com/viewtopic.php?p=1295351055
//+------------------------------------------------------------------
//|
//+------------------------------------------------------------------
#property copyright "mladen"
#property link      "www.forex-station.com"

#property indicator_separate_window
#property indicator_buffers 9
#property indicator_color1  clrDodgerBlue
#property indicator_color2  clrSilver
#property indicator_color3  clrSandyBrown
#property indicator_color4  clrDimGray
#property indicator_style1  STYLE_DOT
#property indicator_style2  STYLE_DOT
#property indicator_style3  STYLE_DOT
#property indicator_minimum  -0.1
#property indicator_maximum  1.1
#property strict

//
//
//
//
//
enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average,    // Average (high+low+open+close)/4
   pr_medianb,    // Average median body (open+close)/2
   pr_tbiased,    // Trend biased price
   pr_highlow,    // High/low
   pr_tbiased2,   // Trend biased (extreme) price
   pr_haclose,    // Heiken ashi close
   pr_haopen ,    // Heiken ashi open
   pr_hahigh,     // Heiken ashi high
   pr_halow,      // Heiken ashi low
   pr_hamedian,   // Heiken ashi median
   pr_hatypical,  // Heiken ashi typical
   pr_haweighted, // Heiken ashi weighted
   pr_haaverage,  // Heiken ashi average
   pr_hamedianb,  // Heiken ashi median body
   pr_hatbiased,  // Heiken ashi trend biased price
   pr_hatbiased2, // Heiken ashi trend biased (extreme) price
   pr_hahighlow   // Heiken ashi high/low
};
enum enMaTypes
{
   ma_sma,    // Simple moving average
   ma_ema,    // Exponential moving average
   ma_smma,   // Smoothed MA
   ma_lwma,   // Linear weighted MA
   ma_tema    // Triple exponential moving average - TEMA
};
enum enColorOn
{
   cc_onSlope,   // Change color on slope change
   cc_onMiddle,  // Change color on middle line cross
   cc_onLevels   // Change color on outer levels cross
};
enum enLevelType
{
   lvl_floa,  // Floating levels
   lvl_quan,  // Quantile levels
   lvl_fixed  // Fixed levels
};

extern ENUM_TIMEFRAMES TimeFrame         = PERIOD_CURRENT; // Time frame tp use
extern int             RsiPeriod         = 14;             // Rsi calculation period
extern int             RsiDepth          = 10;             // Rsi calculation depth
extern bool            RsiFast           = false;          // Use "fast" claculation
extern enPrices        Price             = pr_typical;     // Price to use
extern int             PriceSmooth       = 9;              // Price smoothing period
extern enMaTypes       PriceSmoothMethod = ma_sma;         // Price smoothing method
extern enLevelType     LevelType         = lvl_fixed;      // Level type : 
extern int             MinMaxPeriod      = 25;             // Floating levels period (<= 1 for fixed levels)
extern double          LevelUp           = 90.0;           // Up level %
extern double          LevelDown         = 10.0;           // Down level %
extern enColorOn       ColorOn           = cc_onLevels;    // Color change on :
extern color           ColorUp           = clrDeepSkyBlue; // Color for up
extern color           ColorDown         = clrSandyBrown;  // Color for down
extern color           ShadowColor       = clrGray;        // Shadow color
extern int             LineWidth         = 3;              // Main line width
extern int             ShadowWidth       = 0;              // Shadow width (<=0 main line width+3) 
extern bool            alertsOn          = false;          // Turn alerts on?
extern bool            alertsOnCurrent   = false;          // Alerts on still opened bar?
extern bool            alertsMessage     = true;           // Alerts should display message?
extern bool            alertsSound       = false;          // Alerts should play a sound?
extern bool            alertsNotify      = false;          // Alerts should send a notification?
extern bool            alertsEmail       = false;          // Alerts should send an email?
extern string          soundFile         = "alert2.wav";   // Sound file
extern bool            Interpolate       = true;           // Interpolate in mtf mode?

double rsi[],buffer1da[],buffer1db[],buffer1ua[],buffer1ub[],levup[],levmi[],levdn[],trend[],shadowa[],shadowb[],count[];

string indicatorFileName;
#define _mtfCall(_buff,_ind) iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,RsiPeriod,RsiDepth,RsiFast,Price,PriceSmooth,PriceSmoothMethod,LevelType,MinMaxPeriod,LevelUp,LevelDown,ColorOn,ColorUp,ColorDown,ShadowColor,LineWidth,ShadowWidth,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,soundFile,_buff,_ind)

//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------
//
//
//
//
//

int init()
{
   int shadowWidth = (ShadowWidth<=0) ? LineWidth+3 : ShadowWidth;
   IndicatorBuffers(12);
   SetIndexBuffer(0, levup);
   SetIndexBuffer(1, levmi);
   SetIndexBuffer(2, levdn);
   SetIndexBuffer(3, rsi);       SetIndexStyle(3,EMPTY,EMPTY,LineWidth);
   SetIndexBuffer(4, shadowa);   SetIndexStyle(4,EMPTY,EMPTY,shadowWidth,ShadowColor);
   SetIndexBuffer(5, shadowb);   SetIndexStyle(5,EMPTY,EMPTY,shadowWidth,ShadowColor);
   SetIndexBuffer(6, buffer1ua); SetIndexStyle(6,EMPTY,EMPTY,LineWidth,ColorUp);
   SetIndexBuffer(7 ,buffer1ub); SetIndexStyle(7,EMPTY,EMPTY,LineWidth,ColorUp);
   SetIndexBuffer(8, buffer1da); SetIndexStyle(8,EMPTY,EMPTY,LineWidth,ColorDown);
   SetIndexBuffer(9, buffer1db); SetIndexStyle(9,EMPTY,EMPTY,LineWidth,ColorDown);
   SetIndexBuffer(10,trend);
   SetIndexBuffer(11,count);
   
      RsiDepth          = fmax(MathMin(RsiDepth,25),2);
      indicatorFileName = WindowExpertName();
      TimeFrame         = fmax(TimeFrame,_Period);  
      
   IndicatorShortName(timeFrameToString(TimeFrame)+" Composite RSI ("+(string)RsiPeriod+","+(string)RsiDepth+")");
return(0);
}
int deinit() 
{ 
return(0);
}

//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int i,counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = fmin(Bars-counted_bars,Bars-1); count[0]=limit;
            if (TimeFrame!=_Period)
            {
               limit = (int)fmax(limit,fmin(Bars-1,_mtfCall(11,0)*TimeFrame/_Period));
               if (trend[limit]==-1) { CleanPoint(limit,buffer1da,buffer1db); CleanPoint(limit,shadowa,shadowb); }
               if (trend[limit]== 1) { CleanPoint(limit,buffer1ua,buffer1ub); CleanPoint(limit,shadowa,shadowb); }
               for (i=limit;i>=0 && !_StopFlag; i--)
               {
                  int y = iBarShift(NULL,TimeFrame,Time[i]);
                     levup[i]     = _mtfCall(0,y);
                     levmi[i]     = _mtfCall(1,y);
                     levdn[i]     = _mtfCall(2,y);
                     rsi[i]       = _mtfCall(3,y);
                     buffer1da[i] = EMPTY_VALUE;
                     buffer1db[i] = EMPTY_VALUE;
                     buffer1ua[i] = EMPTY_VALUE;
                     buffer1ub[i] = EMPTY_VALUE;
                     shadowa[i]   = EMPTY_VALUE;
                     shadowb[i]   = EMPTY_VALUE;
                     trend[i]     = _mtfCall(10,y);
                     
                     //
                     //
                     //
                     //
                     //
                     
                     if (!Interpolate || (i>0 && y==iBarShift(NULL,TimeFrame,Time[i-1]))) continue;
                        #define _interpolate(buff) buff[i+k] = buff[i]+(buff[i+n]-buff[i])*k/n
                        int n,k; datetime time = iTime(NULL,TimeFrame,y);
                           for(n = 1; (i+n)<Bars && Time[i+n] >= time; n++) continue;	
                           for(k = 1; k<n && (i+n)<Bars && (i+k)<Bars; k++) 
                           {
                              _interpolate(levup);
                              _interpolate(levmi);
                              _interpolate(levdn);
                              _interpolate(rsi);
                          }                           
               }
               for(i=limit; i>=0; i--)
               {
                  if (trend[i] == -1) { PlotPoint(i,buffer1da,buffer1db,rsi); PlotPoint(i,shadowa,shadowb,rsi); }
                  if (trend[i] ==  1) { PlotPoint(i,buffer1ua,buffer1ub,rsi); PlotPoint(i,shadowa,shadowb,rsi); }
               }
      return(0);
      }
      
      //
      //
      //
      //
      //
      
      int    colorOn = (MinMaxPeriod>0) ? ColorOn : cc_onSlope;
      if (trend[limit]==-1) { CleanPoint(limit,buffer1da,buffer1db); CleanPoint(limit,shadowa,shadowb); }
      if (trend[limit]== 1) { CleanPoint(limit,buffer1ua,buffer1ub); CleanPoint(limit,shadowa,shadowb); }
      for(i = limit; i >= 0 ; i--)
      {
         rsi[i] = iCompRsi(iCustomMa(PriceSmoothMethod,getPrice(Price,Open,Close,High,Low,i),PriceSmooth,i),RsiPeriod,RsiDepth,RsiFast,i);
         buffer1da[i] = EMPTY_VALUE;
         buffer1db[i] = EMPTY_VALUE;
         buffer1ua[i] = EMPTY_VALUE;
         buffer1ub[i] = EMPTY_VALUE;
         shadowa[i]   = EMPTY_VALUE;
         shadowb[i]   = EMPTY_VALUE;
         double hi = rsi[i]; double lo = rsi[i];
         switch (LevelType)
         {
                case lvl_fixed: 
                     levup[i] = LevelUp/100;
                     levdn[i] = LevelDown/100;
                     levmi[i] = (levup[i]+levdn[i])/2;
                     break;
                case lvl_floa:                     
                {               
                    if (MinMaxPeriod>0)
                    {
                      hi = rsi[ArrayMaximum(rsi,MinMaxPeriod,i)];
                      lo = rsi[ArrayMinimum(rsi,MinMaxPeriod,i)];
                      hi = lo+(hi-lo)*LevelUp  /100.0;
                      lo = lo+(hi-lo)*LevelDown/100.0;
                    }                     
                      levup[i] = hi;
                      levdn[i] = lo;
                      levmi[i] = (levup[i]+levdn[i])/2.0;
                      break;
                 }
                 default:                                                
                       levup[i] = iQuantile(rsi[i],MinMaxPeriod, LevelUp               ,i,Bars);
                       levdn[i] = iQuantile(rsi[i],MinMaxPeriod, LevelDown             ,i,Bars);
                       levmi[i] = iQuantile(rsi[i],MinMaxPeriod,(LevelUp+LevelDown)*0.5,i,Bars);
                       break;
            }  
            switch(colorOn)
            {
               case cc_onLevels:         trend[i] = (rsi[i]>levup[i]) ? 1 : (rsi[i]<levdn[i]) ? -1 : 0; break;
               case cc_onMiddle:         trend[i] = (rsi[i]>levmi[i]) ? 1 : (rsi[i]<levmi[i]) ? -1 : 0; break;
               default :  if (i<Bars-1)  trend[i] = (rsi[i]>rsi[i+1]) ? 1 : (rsi[i]<rsi[i+1]) ? -1 : trend[i+1];
            }                  
            if (trend[i] == -1) { PlotPoint(i,buffer1da,buffer1db,rsi); PlotPoint(i,shadowa,shadowb,rsi); }
            if (trend[i] ==  1) { PlotPoint(i,buffer1ua,buffer1ub,rsi); PlotPoint(i,shadowa,shadowb,rsi); }     
     }
     manageAlerts();
return(0);
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

double workCompRsi[][26];
double iCompRsi(double price, double period, int depth, bool fast, int i, int instanceNo=0)
{
   if (ArrayRange(workCompRsi,0) !=Bars) ArrayResize(workCompRsi,Bars); i = Bars-i-1; 
   double alpha = 2.0/(1.0 + period);
   if (fast) alpha = 2.0/(2.0 + (period-1.0)/2.0);
   instanceNo *= 26; depth = (int)MathMin(depth,25);
   
   //
   //
   //
   //
   //
   
   double CU = 0;
   double CD = 0;
   for (int k=0; k<=depth; k++)
   {
      if (i == 0)
            workCompRsi[i][instanceNo+k] = price;
      else  workCompRsi[i][instanceNo+k] = workCompRsi[i-1][instanceNo+k]+alpha*(price-workCompRsi[i-1][instanceNo+k]);

      //
      //
      //
      //
      //
         
      price = workCompRsi[i][k+instanceNo];
      if (k>0)
         if (workCompRsi[i][instanceNo+k-1] >= workCompRsi[i][instanceNo+k])
              CU += workCompRsi[i][instanceNo+k-1] - workCompRsi[i][instanceNo+k  ];
         else CD += workCompRsi[i][instanceNo+k  ] - workCompRsi[i][instanceNo+k-1];
   }
   double trsi = 0; if (CU + CD != 0) trsi = CU / (CU + CD); 
   return(trsi);
}

//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------
//
//
//
//
//

#define _maInstances 2
#define _maWorkBufferx1 1*_maInstances
#define _maWorkBufferx2 2*_maInstances
#define _maWorkBufferx3 3*_maInstances

double iCustomMa(int mode, double price, double length, int r, int instanceNo=0)
{
   int bars = Bars; r = bars-r-1;
   switch (mode)
   {
      case ma_sma   : return(iSma(price,(int)length,r,bars,instanceNo));
      case ma_ema   : return(iEma(price,length,r,bars,instanceNo));
      case ma_smma  : return(iSmma(price,(int)length,r,bars,instanceNo));
      case ma_lwma  : return(iLwma(price,(int)length,r,bars,instanceNo));
      case ma_tema  : return(iTema(price,(int)length,r,bars,instanceNo));
      default       : return(price);
   }
}

//
//
//
//
//

double workSma[][_maWorkBufferx2];
double iSma(double price, int period, int r, int _bars, int instanceNo=0)
{
   if (ArrayRange(workSma,0)!= _bars) ArrayResize(workSma,_bars); instanceNo *= 2; int k;

   workSma[r][instanceNo+0] = price;
   workSma[r][instanceNo+1] = price; for(k=1; k<period && (r-k)>=0; k++) workSma[r][instanceNo+1] += workSma[r-k][instanceNo+0];  
   workSma[r][instanceNo+1] /= 1.0*k;
   return(workSma[r][instanceNo+1]);
}

//
//
//
//
//

double workEma[][_maWorkBufferx1];
double iEma(double price, double period, int r, int _bars, int instanceNo=0)
{
   if (ArrayRange(workEma,0)!= _bars) ArrayResize(workEma,_bars);

   workEma[r][instanceNo] = price;
   if (r>0 && period>1)
          workEma[r][instanceNo] = workEma[r-1][instanceNo]+(2.0/(1.0+period))*(price-workEma[r-1][instanceNo]);
   return(workEma[r][instanceNo]);
}

//
//
//
//
//

double workSmma[][_maWorkBufferx1];
double iSmma(double price, double period, int r, int _bars, int instanceNo=0)
{
   if (ArrayRange(workSmma,0)!= _bars) ArrayResize(workSmma,_bars);

   workSmma[r][instanceNo] = price;
   if (r>1 && period>1)
          workSmma[r][instanceNo] = workSmma[r-1][instanceNo]+(price-workSmma[r-1][instanceNo])/period;
   return(workSmma[r][instanceNo]);
}

//
//
//
//
//

double workLwma[][_maWorkBufferx1];
double iLwma(double price, double period, int r, int _bars, int instanceNo=0)
{
   if (ArrayRange(workLwma,0)!= _bars) ArrayResize(workLwma,_bars);
   
   workLwma[r][instanceNo] = price; if (period<=1) return(price);
      double sumw = period;
      double sum  = period*price;

      for(int k=1; k<period && (r-k)>=0; k++)
      {
         double weight = period-k;
                sumw  += weight;
                sum   += weight*workLwma[r-k][instanceNo];  
      }             
      return(sum/sumw);
}

double workTema[][_maWorkBufferx3];
#define _tema1 0
#define _tema2 1
#define _tema3 2

double iTema(double price, double period, int r, int bars, int instanceNo=0)
{
   if (period<=1) return(price);
   if (ArrayRange(workTema,0)!= bars) ArrayResize(workTema,bars); instanceNo*=3;

   //
   //
   //
   //
   //
      
   workTema[r][_tema1+instanceNo] = price;
   workTema[r][_tema2+instanceNo] = price;
   workTema[r][_tema3+instanceNo] = price;
   double alpha = 2.0 / (1.0+period);
   if (r>0)
   {
          workTema[r][_tema1+instanceNo] = workTema[r-1][_tema1+instanceNo]+alpha*(price                         -workTema[r-1][_tema1+instanceNo]);
          workTema[r][_tema2+instanceNo] = workTema[r-1][_tema2+instanceNo]+alpha*(workTema[r][_tema1+instanceNo]-workTema[r-1][_tema2+instanceNo]);
          workTema[r][_tema3+instanceNo] = workTema[r-1][_tema3+instanceNo]+alpha*(workTema[r][_tema2+instanceNo]-workTema[r-1][_tema3+instanceNo]); }
   return(workTema[r][_tema3+instanceNo]+3.0*(workTema[r][_tema1+instanceNo]-workTema[r][_tema2+instanceNo]));
}

//-------------------------------------------------------------------
//                                                                  
//-------------------------------------------------------------------
//
//
//
//
//

#define _quantileInstances 1
double _sortQuant[];
double _workQuant[][_quantileInstances];

double iQuantile(double value, int period, double qp, int i, int bars, int instanceNo=0)
{
   if (period<1) return(value);
   if (ArrayRange(_workQuant,0)!=bars) ArrayResize(_workQuant,bars); 
   if (ArraySize(_sortQuant)!=period)  ArrayResize(_sortQuant,period); 
            i=bars-i-1; _workQuant[i][instanceNo]=value;
            int k=0; for (; k<period && (i-k)>=0; k++) _sortQuant[k] = _workQuant[i-k][instanceNo];
                     for (; k<period            ; k++) _sortQuant[k] = 0;
                     ArraySort(_sortQuant);

   //
   //
   //
   //
   //
   
   double index = (period-1.0)*qp/100.00;
   int    ind   = (int)index;
   double delta = index - ind;
   if (ind == NormalizeDouble(index,5))
         return(            _sortQuant[ind]);
   else  return((1.0-delta)*_sortQuant[ind]+delta*_sortQuant[ind+1]);
}   

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
//

#define priceInstances 1
double workHa[][priceInstances*4];
double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int instanceNo=0)
{
  if (tprice>=pr_haclose)
   {
      if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); instanceNo*=4;
         int r = Bars-i-1;
         
         //
         //
         //
         //
         //
         
         double haOpen;
         if (r>0)
                haOpen  = (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0;
         else   haOpen  = (open[i]+close[i])/2;
         double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0;
         double haHigh  = fmax(high[i],fmax(haOpen,haClose));
         double haLow   = fmin(low[i] ,fmin(haOpen,haClose));

         if(haOpen<haClose) { workHa[r][instanceNo+0] = haLow;  workHa[r][instanceNo+1] = haHigh; } 
         else               { workHa[r][instanceNo+0] = haHigh; workHa[r][instanceNo+1] = haLow;  } 
                              workHa[r][instanceNo+2] = haOpen;
                              workHa[r][instanceNo+3] = haClose;
         //
         //
         //
         //
         //
         
         switch (tprice)
         {
            case pr_haclose:     return(haClose);
            case pr_haopen:      return(haOpen);
            case pr_hahigh:      return(haHigh);
            case pr_halow:       return(haLow);
            case pr_hamedian:    return((haHigh+haLow)/2.0);
            case pr_hamedianb:   return((haOpen+haClose)/2.0);
            case pr_hatypical:   return((haHigh+haLow+haClose)/3.0);
            case pr_haweighted:  return((haHigh+haLow+haClose+haClose)/4.0);
            case pr_haaverage:   return((haHigh+haLow+haClose+haOpen)/4.0);
            case pr_hatbiased:
               if (haClose>haOpen)
                     return((haHigh+haClose)/2.0);
               else  return((haLow+haClose)/2.0);        
            case pr_hatbiased2:
               if (haClose>haOpen)  return(haHigh);
               if (haClose<haOpen)  return(haLow);
                                    return(haClose);        
         }
   }
   
   //
   //
   //
   //
   //
   
   switch (tprice)
   {
      case pr_close:     return(close[i]);
      case pr_open:      return(open[i]);
      case pr_high:      return(high[i]);
      case pr_low:       return(low[i]);
      case pr_median:    return((high[i]+low[i])/2.0);
      case pr_medianb:   return((open[i]+close[i])/2.0);
      case pr_typical:   return((high[i]+low[i]+close[i])/3.0);
      case pr_weighted:  return((high[i]+low[i]+close[i]+close[i])/4.0);
      case pr_average:   return((high[i]+low[i]+close[i]+open[i])/4.0);
      case pr_tbiased:   
               if (close[i]>open[i])
                     return((high[i]+close[i])/2.0);
               else  return((low[i]+close[i])/2.0);        
      case pr_tbiased2:   
               if (close[i]>open[i]) return(high[i]);
               if (close[i]<open[i]) return(low[i]);
                                     return(close[i]);        
   }
return(0);
}   

//-------------------------------------------------------------------
//                                                                  
//-------------------------------------------------------------------
//
//
//
//
//

void CleanPoint(int i,double& first[],double& second[])
{
   if (i>=Bars-3) return;
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (i>=Bars-2) return;
   if (first[i+1] == EMPTY_VALUE)
      if (first[i+2] == EMPTY_VALUE) 
            { first[i]  = from[i]; first[i+1]  = from[i+1]; second[i] = EMPTY_VALUE; }
      else  { second[i] = from[i]; second[i+1] = from[i+1]; first[i]  = EMPTY_VALUE; }
   else     { first[i]  = from[i];                          second[i] = EMPTY_VALUE; }
}

//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

void manageAlerts()
{
   if (alertsOn)
   {
      int whichBar = 1; if (alertsOnCurrent) whichBar = 0;
      if (trend[whichBar] != trend[whichBar+1])
      {
         if (trend[whichBar] == 1) doAlert(whichBar,"up");
         if (trend[whichBar] ==-1) doAlert(whichBar,"down");
      }         
   }
}   

//
//
//
//
//

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message = timeFrameToString(_Period)+" "+Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" Composite Rsi "+doWhat;
          if (alertsMessage) Alert(message);
          if (alertsNotify)  SendNotification(message);
          if (alertsEmail)   SendMail(StringConcatenate(Symbol()," Composite Rsi "),message);
          if (alertsSound)   PlaySound(soundFile);
   }
}