questions about indicator RSI

 

hi guys i want modyfy a RSI in metatrader i want place in one time 2 indicator of RSI in one separated window, and i would when  cross first rsi over second appear an allert , i try to mod ,a RSI  in MT4 but i dont know  why i can visualize only firs RSI

this is my code   anyone can suggest  me  some idea ?? thankz

//+------------------------------------------------------------------+
//|                                                          RSI.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Relative Strength Index"
#property strict

#property indicator_separate_window
#property indicator_minimum    0
#property indicator_maximum    100
#property indicator_buffers    1
#property indicator_color1     DodgerBlue
#property indicator_level1     30.0
#property indicator_level2     70.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//--- input parameters
input int InpRSIPeriod=4; // RSI Period
input int InpRSIPeriod2=432; // RSI Period
//--- buffers
double ExtRSIBuffer[];
double ExtPosBuffer[];
double ExtNegBuffer[];
double ExtRSIBuffer2[];
double ExtPosBuffer2[];
double ExtNegBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
//--- 2 additional buffers are used for counting.
   IndicatorBuffers(6);
   SetIndexBuffer(1,ExtPosBuffer);
   SetIndexBuffer(2,ExtNegBuffer);
   SetIndexBuffer(4,ExtPosBuffer2);
   SetIndexBuffer(5,ExtNegBuffer2);
//--- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtRSIBuffer);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtRSIBuffer2);
//--- name for DataWindow and indicator subwindow label
   short_name="-";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--- check for input
   if((InpRSIPeriod<2)||(InpRSIPeriod2<2))
     {
      Print("Incorrect value for input variable InpRSIPeriod = ",InpRSIPeriod);
      return(INIT_FAILED);
     }
//---
   SetIndexDrawBegin(3,InpRSIPeriod2);
   SetIndexDrawBegin(0,InpRSIPeriod);

//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
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    i,pos;
   double diff;
   int    i2,pos2;
   double diff2;
//---
   if(Bars<=InpRSIPeriod || InpRSIPeriod<2)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtRSIBuffer,false);
   ArraySetAsSeries(ExtPosBuffer,false);
   ArraySetAsSeries(ExtNegBuffer,false);

   ArraySetAsSeries(ExtRSIBuffer2,false);
   ArraySetAsSeries(ExtPosBuffer2,false);
   ArraySetAsSeries(ExtNegBuffer2,false);
   ArraySetAsSeries(close,false);
//--- preliminary calculations
   pos=prev_calculated-1;
   pos2=prev_calculated-1;
   if(pos2<=InpRSIPeriod2)
     {
      ExtRSIBuffer2[0]=0.0;
      ExtPosBuffer2[0]=0.0;
      ExtNegBuffer2[0]=0.0;

      double sump2=0.0;
      double sumn2=0.0;
      for(i2=1; i2<=InpRSIPeriod2; i2++)
        {
         ExtRSIBuffer2[i]=0.0;
         ExtPosBuffer2[i]=0.0;
         ExtNegBuffer2[i]=0.0;
         diff2=close[i2]-close[i2-1];
         if(diff2>0)
            sump2+=diff2;
         else
            sumn2-=diff2;
        }
     }


   if(pos<=InpRSIPeriod)
     {
      //--- first RSIPeriod values of the indicator are not calculated
      ExtRSIBuffer[0]=0.0;
      ExtPosBuffer[0]=0.0;
      ExtNegBuffer[0]=0.0;

      double sump=0.0;
      double sumn=0.0;
      for(i=1; i<=InpRSIPeriod; i++)
        {
         ExtRSIBuffer[i]=0.0;
         ExtPosBuffer[i]=0.0;
         ExtNegBuffer[i]=0.0;


         diff=close[i]-close[i-1];
         if(diff>0)
            sump+=diff;
         else
            sumn-=diff;
        }
      //--- calculate first visible value
      ExtPosBuffer[InpRSIPeriod]=sump/InpRSIPeriod;
      ExtNegBuffer[InpRSIPeriod]=sumn/InpRSIPeriod;

      if(ExtNegBuffer[InpRSIPeriod]!=0.0)
        {
         ExtRSIBuffer[InpRSIPeriod]=100.0-(100.0/(1.0+ExtPosBuffer[InpRSIPeriod]/ExtNegBuffer[InpRSIPeriod]));
        }
      else
        {
         if(ExtPosBuffer[InpRSIPeriod]!=0.0)
           {
            ExtRSIBuffer[InpRSIPeriod]=100.0;
           }
         else
            ExtRSIBuffer[InpRSIPeriod]=50.0;
        }


      ExtPosBuffer2[InpRSIPeriod2]=sump/InpRSIPeriod2;
      ExtNegBuffer2[InpRSIPeriod2]=sumn/InpRSIPeriod2;

      if(ExtNegBuffer2[InpRSIPeriod2]!=0.0)
        {
         ExtRSIBuffer2[InpRSIPeriod2]=100.0-(100.0/(1.0+ExtPosBuffer2[InpRSIPeriod2]/ExtNegBuffer2[InpRSIPeriod2]));
        }
      else
        {
         if(ExtPosBuffer2[InpRSIPeriod2]!=0.0)
           {

            ExtRSIBuffer2[InpRSIPeriod2]=100.0;
           }
         else

            ExtRSIBuffer2[InpRSIPeriod2]=50.0;
        }
      //--- prepare the position value for main calculation
      pos=InpRSIPeriod+1;
      pos2=InpRSIPeriod2+1;
     }
//--- the main loop of calculations

   for(i=pos; i<rates_total && !IsStopped(); i++)
     {
      diff=close[i]-close[i-1];
      ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod;
      ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod;
      if(ExtNegBuffer[i]!=0.0)
        {
         ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]);
        }
      else
        {
         if(ExtPosBuffer[i]!=0.0)
           {
            ExtRSIBuffer[i]=100.0;
           }
         else
            ExtRSIBuffer[i]=50.0;
        }

     }

   for(i2=pos2; i2<rates_total && !IsStopped(); i2++)
     {
      diff2=close[i2]-close[i2-1];
      ExtPosBuffer2[i2]=(ExtPosBuffer2[i2-1]*(InpRSIPeriod2-1)+(diff2>0.0?diff2:0.0))/InpRSIPeriod2;
      ExtNegBuffer2[i2]=(ExtNegBuffer2[i2-1]*(InpRSIPeriod2-1)+(diff2<0.0?-diff2:0.0))/InpRSIPeriod2;

      if(ExtNegBuffer2[i2]!=0.0)
        {
         ExtRSIBuffer2[i2]=100.0-100.0/(1+ExtPosBuffer2[i2]/ExtNegBuffer2[i2]);
        }
      else
        {
         if(ExtPosBuffer2[i2]!=0.0)
           {
            ExtRSIBuffer2[i2]=100.0;
           }
         else
            ExtRSIBuffer2[i2]=50.0;
        }
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
#property indicator_buffers    2
#property indicator_color1     clrDodgerBlue
#property indicator_color2     clrRed
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, ExtRSIBuffer);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, ExtRSIBuffer2);
   SetIndexBuffer(2, ExtPosBuffer);
   SetIndexBuffer(3, ExtNegBuffer);
   SetIndexBuffer(4, ExtPosBuffer2);
   SetIndexBuffer(5, ExtNegBuffer2);

 
faustf: i want modyfy a RSI in metatrader i want place in one time 2 indicator of RSI in one separated window, and i would when  cross first rsi over second appear an allert ,

No need to modify the RSI. Write an indicator that reads iRSI and does the Alert. No need to have the RSIs on the chart unless you need to see them.

 
thank you @Nagisa Unada , thanks @William Roeder i saw iRSI but  for me is necessary see the RSI  thankz again