//+------------------------------------------------------------------+
//|                                         Indicator: +++RSI+++.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "BetyX"
#property link      "betyx2@gmail.com"
#property version   "1.01"
#property description "RSI"

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 12

#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_color1 0x8C8984
#property indicator_label1 "RSI"

#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_color2 0xF2EBDC
#property indicator_label2 "80"

#property indicator_type3 DRAW_LINE
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
#property indicator_color3 0xF2EBDC
#property indicator_label3 "20"

#property indicator_type4 DRAW_LINE
#property indicator_style4 STYLE_SOLID
#property indicator_width4 2
#property indicator_color4 0x90F0CB
#property indicator_label4 "RSI"

#property indicator_type5 DRAW_LINE
#property indicator_style5 STYLE_SOLID
#property indicator_width5 2
#property indicator_color5 0x1DE02A
#property indicator_label5 "RSI"

#property indicator_type6 DRAW_LINE
#property indicator_style6 STYLE_SOLID
#property indicator_width6 2
#property indicator_color6 0x06700D
#property indicator_label6 "RSI"

#property indicator_type7 DRAW_LINE
#property indicator_style7 STYLE_SOLID
#property indicator_width7 2
#property indicator_color7 0xA496EB
#property indicator_label7 "RSI"

#property indicator_type8 DRAW_LINE
#property indicator_style8 STYLE_SOLID
#property indicator_width8 2
#property indicator_color8 0x3611F0
#property indicator_label8 "RSI"

#property indicator_type9 DRAW_LINE
#property indicator_style9 STYLE_SOLID
#property indicator_width9 2
#property indicator_color9 0x1C0785
#property indicator_label9 "RSI"

#property indicator_type10 DRAW_LINE
#property indicator_style10 STYLE_SOLID
#property indicator_width10 2
#property indicator_color10 0x8A8274
#property indicator_label10 "95"

#property indicator_type11 DRAW_LINE
#property indicator_style11 STYLE_SOLID
#property indicator_width11 2
#property indicator_color11 0x8A8274
#property indicator_label11 "5"

#property indicator_type12 DRAW_LINE
#property indicator_style12 STYLE_SOLID
#property indicator_width12 1
#property indicator_color12 0x13D8F2
#property indicator_label12 "50"

#define PLOT_MAXIMUM_BARS_BACK 5000
#define OMIT_OLDEST_BARS 50

//--- indicator buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double Buffer8[];
double Buffer9[];
double Buffer10[];
double Buffer11[];
double Buffer12[];

extern int PowerRSI = 14;
extern double Value80 = 80;
extern double Value20 = 20;
extern double greenlight = 51;
extern double greenHard = 60;
extern double greenHardMax = 75;
extern double redlight = 49;
extern double redHard = 40;
extern double redHardMax = 25;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | +++RSI+++ @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(12);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexDrawBegin(0, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexDrawBegin(1, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(2, Buffer3);
   SetIndexEmptyValue(2, EMPTY_VALUE);
   SetIndexDrawBegin(2, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(3, Buffer4);
   SetIndexEmptyValue(3, EMPTY_VALUE);
   SetIndexDrawBegin(3, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(4, Buffer5);
   SetIndexEmptyValue(4, EMPTY_VALUE);
   SetIndexDrawBegin(4, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(5, Buffer6);
   SetIndexEmptyValue(5, EMPTY_VALUE);
   SetIndexDrawBegin(5, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(6, Buffer7);
   SetIndexEmptyValue(6, EMPTY_VALUE);
   SetIndexDrawBegin(6, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(7, Buffer8);
   SetIndexEmptyValue(7, EMPTY_VALUE);
   SetIndexDrawBegin(7, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(8, Buffer9);
   SetIndexEmptyValue(8, EMPTY_VALUE);
   SetIndexDrawBegin(8, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(9, Buffer10);
   SetIndexEmptyValue(9, EMPTY_VALUE);
   SetIndexDrawBegin(9, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(10, Buffer11);
   SetIndexEmptyValue(10, EMPTY_VALUE);
   SetIndexDrawBegin(10, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   SetIndexBuffer(11, Buffer12);
   SetIndexEmptyValue(11, EMPTY_VALUE);
   SetIndexDrawBegin(11, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
   //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);
   ArraySetAsSeries(Buffer2, true);
   ArraySetAsSeries(Buffer3, true);
   ArraySetAsSeries(Buffer4, true);
   ArraySetAsSeries(Buffer5, true);
   ArraySetAsSeries(Buffer6, true);
   ArraySetAsSeries(Buffer7, true);
   ArraySetAsSeries(Buffer8, true);
   ArraySetAsSeries(Buffer9, true);
   ArraySetAsSeries(Buffer10, true);
   ArraySetAsSeries(Buffer11, true);
   ArraySetAsSeries(Buffer12, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
      ArrayInitialize(Buffer2, EMPTY_VALUE);
      ArrayInitialize(Buffer3, EMPTY_VALUE);
      ArrayInitialize(Buffer4, EMPTY_VALUE);
      ArrayInitialize(Buffer5, EMPTY_VALUE);
      ArrayInitialize(Buffer6, EMPTY_VALUE);
      ArrayInitialize(Buffer7, EMPTY_VALUE);
      ArrayInitialize(Buffer8, EMPTY_VALUE);
      ArrayInitialize(Buffer9, EMPTY_VALUE);
      ArrayInitialize(Buffer10, EMPTY_VALUE);
      ArrayInitialize(Buffer11, EMPTY_VALUE);
      ArrayInitialize(Buffer12, EMPTY_VALUE);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(PLOT_MAXIMUM_BARS_BACK-1, rates_total-1-OMIT_OLDEST_BARS)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i) != 0 //Relative Strength Index is not equal to fixed value
      )
        {
         Buffer1[i] = iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      if(true //no conditions!
      )
        {
         Buffer2[i] = Value80; //Set indicator value at fixed value
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 3
      if(true //no conditions!
      )
        {
         Buffer3[i] = Value20; //Set indicator value at fixed value
        }
      else
        {
         Buffer3[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 4
      if(iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i) > greenlight //Relative Strength Index > fixed value
      )
        {
         Buffer4[i] = iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer4[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 5
      if(iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i) > greenHard //Relative Strength Index > fixed value
      )
        {
         Buffer5[i] = iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer5[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 6
      if(iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i) > greenHardMax //Relative Strength Index > fixed value
      )
        {
         Buffer6[i] = iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer6[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 7
      if(iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i) < redlight //Relative Strength Index < fixed value
      )
        {
         Buffer7[i] = iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer7[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 8
      if(iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i) < redHard //Relative Strength Index < fixed value
      )
        {
         Buffer8[i] = iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer8[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 9
      if(iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i) < redHardMax //Relative Strength Index < fixed value
      )
        {
         Buffer9[i] = iRSI(NULL, PERIOD_CURRENT, PowerRSI, PRICE_CLOSE, i); //Set indicator value at Relative Strength Index
        }
      else
        {
         Buffer9[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 10
      if(true //no conditions!
      )
        {
         Buffer10[i] = 95; //Set indicator value at fixed value
        }
      else
        {
         Buffer10[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 11
      if(true //no conditions!
      )
        {
         Buffer11[i] = 5; //Set indicator value at fixed value
        }
      else
        {
         Buffer11[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 12
      if(true //no conditions!
      )
        {
         Buffer12[i] = 50; //Set indicator value at fixed value
        }
      else
        {
         Buffer12[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+