RSI Multiple Time Frames

To add comments, please log in or register
mcetraro
29
mcetraro  

Hello,

First of all, I want to thank you for your help. Any ideas or sample code will be appreciated very much.  I have spent days trying to solve this and I couldn't.

Problem:

I am trying to create an array that contains the RSI values of a tf up.  For example. If my current tf is H1, I would like to populate the array with the vaues of the H4 RSI values.  I get all the time the famous error "out of range".  Below my code:

William Roeder
20808
William Roeder  
mcetraro: Below my code:

Edit your original post and try again.

mcetraro
29
mcetraro  
First of all, I want to thank you in advance for any help with this issue. I have spent more than a week working several hours on the problem.If you have a simple example it will great too.
Problem:
Basically my problem is related to a multi time frame. I have an indicator that placed an arrow up or down depending on certain conditions. I need to create a H4 RSI loop in a H1 current time frame. This loop will create and place the H4 RSI in an array. I don't need to display anything. I want only the values in an array.  The code that I am attaching is showing the H1 RSI loop and the RSIMAArray of the H1 RSI. I need to insert a loop that populates an Array with the H4 RSI values and another with the H$ RSIMAArray. 
#property copyright "Copyright 2015"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 clrRed
#property indicator_color2 clrBlack
#property indicator_color3 clrBlack
#property indicator_color4 clrBlue
#property indicator_color5 clrRed
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_levelstyle STYLE_DASH
#property indicator_levelcolor clrRed
//#property indicator_minimum 0
//#property indicator_maximum 100

extern int ATRPeriod =8;//ATR Period
extern int RSIPeriod =8;//RSI Period
extern int LookBack =102;//LookBack Period
extern int MAPeriod = 5;//MA Period
extern int BBPeriod = 8;//BB Period
extern int TimeFrame = 240;
extern double levels = 0.0000;

double ATRBuffer[];
double UpLimit[];
double DownLimit[];
double UpArrow[];
double DownArrow[];
double RSIArray[];
double RSIArray4H[];
double RSIMAArray[];
double RSIMAArray4H[];
double RSImaxvalue[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//IndicatorBuffers(4);
//--- indicator buffers mapping
   SetIndexBuffer(0,ATRBuffer);
   SetIndexStyle(0,DRAW_LINE);
//---
   SetIndexBuffer(1,UpLimit);
   SetIndexStyle(1,DRAW_LINE);
//---
   SetIndexBuffer(2,DownLimit);
   SetIndexStyle(2,DRAW_LINE);
//---
   SetIndexBuffer(3,UpArrow);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,233);
//---
   SetIndexBuffer(4,DownArrow);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,234);

   SetIndexBuffer(5,RSIArray);
   SetIndexStyle(5,DRAW_NONE);

   SetIndexBuffer(6,RSIMAArray);
   SetIndexStyle(6,DRAW_NONE);

   SetIndexBuffer(7,RSImaxvalue);
   SetIndexStyle(7,DRAW_NONE);

//---
   IndicatorShortName("ATR Range("+(string)ATRPeriod+","+(string)LookBack+",)");
   datetime candletime = 0;

//---
   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,i;
   int indexmax = 0;
   int indexmin = 0;
   int indexrsimax = 0;
   double RSIvalue = 0;
   bool up = false;
   bool down = false;
   bool upSignal = false;
   int upSetting = 0;
   double diffBands = 0;
   double closeBar = 0;
   double closeBarVar = 0;
   datetime timeRequested = 0;

   ArraySetAsSeries(UpArrow,true);
   ArraySetAsSeries(DownArrow,true);
   ArraySetAsSeries(RSIArray,true);
   ArraySetAsSeries(RSIMAArray,true);
   ArraySetAsSeries(RSIArray4H,true);
   ArraySetAsSeries(RSIMAArray4H,true);

        
      limit = MathMin(rates_total-1, rates_total-prev_calculated);
        {
         for(i=limit; i>=0; i--)
           {
            ATRBuffer[i]=iATR(NULL,0,ATRPeriod,i);
            RSIArray[i]=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i);
           }


         for(i=limit; i>=0; i--)
           {
            RSIMAArray[i] = iMAOnArray(RSIArray,0,RSIPeriod,0,MODE_EMA,i);
           }

         for(i=limit; i>=0; i--)
           {
            double RSICurrent=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i);
            double RSICurrentH4=iRSI(NULL,240,RSIPeriod,PRICE_CLOSE,i);
            double RSIPrevious=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i+1);
            double RSIPreviousH4=iRSI(NULL,240,RSIPeriod,PRICE_CLOSE,i+1);
            double RSIPrevious2=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i+2);
            double ATRCurrent=iATR(NULL,0,ATRPeriod,i);
            double ATRPrevious=iATR(NULL,0,ATRPeriod,i+1);
            double ATRPrevious2=iATR(NULL,0,ATRPeriod,i+2);
            double MACurrent = iMA(NULL, PERIOD_CURRENT, MAPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
            double MAPrevious = iMA(NULL, PERIOD_CURRENT, MAPeriod, 0, MODE_EMA, PRICE_CLOSE, i+1);
            double BBandMain = iBands(NULL,0,BBPeriod,2.5,0,PRICE_CLOSE,0,i);
            double BBandMainPrevious = iBands(NULL,0,BBPeriod,2.5,0,PRICE_CLOSE,0,i+1);
            double BBandUp = iBands(NULL,0,BBPeriod,2.5,0,PRICE_CLOSE,1,i);
            double BBandUpPrevious = iBands(NULL,0,BBPeriod,2.5,0,PRICE_CLOSE,1,i+1);
            double BBandDown = iBands(NULL,0,BBPeriod,2.5,0,PRICE_CLOSE,2,i);
            double BBandDownPrevious 

 If you need more information, just let me know.

Thank you very much.
William Roeder
20808
William Roeder  
       for(i=limit; i>=0; i--)
           {
            double RSICurrent=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i);
            double RSICurrentH4=iRSI(NULL,240,RSIPeriod,PRICE_CLOSE,i);
            double RSIPrevious=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i+1);
            double RSIPreviousH4=iRSI(NULL,240,RSIPeriod,PRICE_CLOSE,i+1);
  1. You are mixing apples and oranges.

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4
Jean Francois Le Bas
1100
Jean Francois Le Bas  
mcetraro:
First of all, I want to thank you in advance for any help with this issue. I have spent more than a week working several hours on the problem.If you have a simple example it will great too.
Problem:
Basically my problem is related to a multi time frame. I have an indicator that placed an arrow up or down depending on certain conditions. I need to create a H4 RSI loop in a H1 current time frame. This loop will create and place the H4 RSI in an array. I don't need to display anything. I want only the values in an array.  The code that I am attaching is showing the H1 RSI loop and the RSIMAArray of the H1 RSI. I need to insert a loop that populates an Array with the H4 RSI values and another with the H$ RSIMAArray. 
 If you need more information, just let me know.

Thank you very much.

you need to use iBarShift to access the right shift for Periods different than the actual period, because if you set the same shift, it work work well (you can't access the same 2 bars ago on H1 and M1)

To add comments, please log in or register