Bring Indicator Buffers to CArrayObj

 

Hello guys,

I wanna iterate thru indicator buffers of different timeframes/periods and check for signals.

#include <Arrays\ArrayObj.mqh>
CArrayObj            m_arr;

//params for rsi indicator
double               RSI_M1[];
double               RSI_M5[];
int                  RSI_handle_M1;
int                  RSI_handle_M5;
uchar                rsiPeriods = 14;

int OnInit()
{
   RSI_handle_M1=iRSI(_Symbol,PERIOD_M1,rsiPeriods,PRICE_CLOSE);
   if(RSI_handle_M1<0)
     {
      Print("The creation has failed: Runtime error =",GetLastError());
      return(-1);
     }
   RSI_handle_M5=iRSI(_Symbol,PERIOD_M5,rsiPeriods,PRICE_CLOSE);
   if(RSI_handle_M5<0)
     {
      Print("The creation has failed: Runtime error =",GetLastError());
      return(-1);
     }
}

void OnTick()
  {
        ...     
        if(!CopyBufferAsSeries(RSI_handle_M1,0,0,100,true,RSI_M1)) return;
        if(!CopyBufferAsSeries(RSI_handle_M5,0,0,100,true,RSI_M5)) return;

        ...
        //so now I have two buffers with 100 double entrys RSI_M1 and RSI_M5 
        //I wanna add RSI_M1 and RSI_M5 into a iteratable object to move from period to period an check for signals

        m_arr.AddArray(RSI_M1); //=> doesnt work  "'RSI_M1' - array required"
        m_arr.AddArray(RSI_M5); //=> doesnt work  "'RSI_M5' - array required"

        //And then I wanna do something like that...
        for (int i=0; i<ArraySize(m_arr);i++)
                //do some fancy stuff...
                if(m_arr[i[0]]>30) someSignalIn_RSI_i;

Iam pretty new at coding with MQL5 and I didnt find any solution in this forum.

I guess its just to easy ...

Do you have any solution to solve this problem?

Best regards

Vi

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
 

Why don't you use CArrayDouble?

#include <Arrays\ArrayDouble.mqh>
CArrayDouble            m_arr;
 

Thank you @lippmaje :)!

It works with that CArrayDouble.

Best regards