//+------------------------------------------------------------------+
//|                                            ARROW DIAMOND RSI.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+


#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Orange
#property indicator_width1 3
#property indicator_color2 Red
#property indicator_width2 3

//=======================================================================================

extern int LineSize       = 3 ;//4
extern int Move_Arrow     = 5 ;

double bBuffer1[];
double sBuffer1[];
double trend[];

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------

int init()
{
   IndicatorBuffers(3);
   SetIndexBuffer(0,bBuffer1); SetIndexStyle(0,DRAW_ARROW,2, LineSize); SetIndexArrow(0,233);
   SetIndexBuffer(1,sBuffer1); SetIndexStyle(1,DRAW_ARROW,2, LineSize); SetIndexArrow(1,234);
   SetIndexBuffer(2,trend);
   return(0);
}   

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
//
//
//
//

int start()
{
   int y,count,counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(MathMax(Bars-counted_bars,2*PERIOD_H1/Period()),Bars-1);

   //
   //
   //
   //
   //

   double RSI5_up  , RSI5_dn;
   double RSI15_up , RSI15_dn;
   double RSI60_up , RSI60_dn;

   for(int i = limit; i >= 0; i--)
   {
         bBuffer1[i] = EMPTY_VALUE; 
         sBuffer1[i] = EMPTY_VALUE;
         trend[i]    = trend[i+1];
         
         y = iBarShift(NULL,PERIOD_M5,Time[i]);
            double RSI5_rsi8 = iRSI(NULL,PERIOD_M5,30,PRICE_CLOSE,y);
            double RSI5_rsi4 = iRSI(NULL,PERIOD_M5,10,PRICE_CLOSE,y);
               if ((RSI5_rsi4 > RSI5_rsi8)) { RSI5_up = 1; RSI5_dn = 0; } 
               if ((RSI5_rsi4 < RSI5_rsi8)) { RSI5_up = 0; RSI5_dn = 1; } 

         y = iBarShift(NULL,PERIOD_M15,Time[i]);
            double RSI15_rsi4 = iRSI(NULL,PERIOD_M15,40,PRICE_CLOSE,y);
            double RSI15_rsi2 = iRSI(NULL,PERIOD_M15,15,PRICE_CLOSE,y);
               if ((RSI15_rsi2 > RSI15_rsi4)) { RSI15_up = 1; RSI15_dn = 0; }
               if ((RSI15_rsi2 < RSI15_rsi4)) { RSI15_up = 0; RSI15_dn = 1; }   

         y = iBarShift(NULL,PERIOD_H1,Time[i]);
            double RSI60_rsi4 = iRSI(NULL,PERIOD_H1,14,PRICE_CLOSE,y);
            double RSI60_rsi2 = iRSI(NULL,PERIOD_H1, 7,PRICE_CLOSE,y);
               if ((RSI60_rsi2 > RSI60_rsi4)) { RSI60_up = 1; RSI60_dn = 0; }
               if ((RSI60_rsi2 < RSI60_rsi4)) { RSI60_up = 0; RSI60_dn = 1; }  

               //
               //
               //
               //
               //
               
               if (RSI5_up==1 && RSI15_up==1 && RSI60_up==1) trend[i] =  1;
               if (RSI5_dn==1 && RSI15_dn==1 && RSI60_dn==1) trend[i] = -1;
               if (trend[i]!=trend[i+1])
               {
                  if (trend[i]== 1) bBuffer1[i] = Low[i] -Move_Arrow*Point;
                  if (trend[i]==-1) sBuffer1[i] = High[i]+Move_Arrow*Point;
               }
   } 
   return(0);
}
 