//+------------------------------------------------------------------+
//|                                  Indicator: ++SuperSmoothRsi.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "BetyX"
#property link      "betyx2@gmail.com"
#property version   "1.00"

#property description "Rsi,++mawiliams1"
#property tester_indicator "++MAWiliams1"

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1

#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_color1 0xFF00F2
#property indicator_label1 "Rsi"

//--- indicator buffers
double Buffer1[];

extern int PowerRsi = 14;
extern int PowerMA = 100;
extern int Power_Shift = 0;
extern int PowerWilo = 42;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | ++SuperSmoothRsi @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(1);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
     }
   else
      limit++;
   
   int j;
   
   double IndicatorData1[];
   int IndicatorData1_count = 2*PowerRsi;
   if(IndicatorData1_count < MathMax(limit, 50)) IndicatorData1_count = MathMax(limit, 50);
   ArrayResize(IndicatorData1, IndicatorData1_count);
   ArraySetAsSeries(IndicatorData1, true);
   for(j = IndicatorData1_count-1; j >= 0; j--)
     {
      IndicatorData1[j] = iCustom(NULL, PERIOD_CURRENT, "++MAWiliams1", PowerMA, Power_Shift, PowerWilo, 0, j); //IndicatorData1 = ++MAWiliams1
     }
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      
      //Indicator Buffer 1
      if(iRSIOnArray(IndicatorData1, 0, PowerRsi, i) != 0 //Relative Strength Index is not equal to fixed value
      )
        {
         Buffer1[i] = iRSIOnArray(IndicatorData1, 0, PowerRsi, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+