Check through all timeframe (RSI)

 

I am checking iRSI indicator with timeframe M1 to D1. for this i am using


string gRandomSymbol = "EURUSD"
extern ENUM_APPLIED_PRICE RSI_AppliedPrice = PRICE_CLOSE;
extern int RSI_Period = 14;
extern int RSI_shift = 0;
extern int RSI_UpLevel = 80;
extern int RSI_BelowLevel = 20;
extern bool PeriodM1 = true;
extern bool PeriodM5 = true;
extern bool PeriodM15 = true;
extern bool PeriodM30 = false;
extern bool PeriodH1 = false;
extern bool PeriodH4 = false;
extern bool PeriodD1 = false;


if(iRSI(gRandomSymbol,PERIOD_M1,RSI_Period,RSI_AppliedPrice,RSI_shift) > RSI_UpLevel &&
                     iRSI(gRandomSymbol,PERIOD_M5,RSI_Period,RSI_AppliedPrice,RSI_shift) > RSI_UpLevel &&
                     iRSI(gRandomSymbol,PERIOD_M15,RSI_Period,RSI_AppliedPrice,RSI_shift) > RSI_UpLevel &&
                     iRSI(gRandomSymbol,PERIOD_M30,RSI_Period,RSI_AppliedPrice,RSI_shift) > RSI_UpLevel &&
                     iRSI(gRandomSymbol,PERIOD_H1,RSI_Period,RSI_AppliedPrice,RSI_shift) > RSI_UpLevel &&
                     iRSI(gRandomSymbol,PERIOD_H4,RSI_Period,RSI_AppliedPrice,RSI_shift) > RSI_UpLevel)
                     gSignalStatus = "RSI_UP";

                  if(iRSI(gRandomSymbol,PERIOD_M1,RSI_Period,RSI_AppliedPrice,RSI_shift) < RSI_BelowLevel &&
                     iRSI(gRandomSymbol,PERIOD_M5,RSI_Period,RSI_AppliedPrice,RSI_shift) < RSI_BelowLevel &&
                     iRSI(gRandomSymbol,PERIOD_M15,RSI_Period,RSI_AppliedPrice,RSI_shift) < RSI_BelowLevel &&
                     iRSI(gRandomSymbol,PERIOD_M30,RSI_Period,RSI_AppliedPrice,RSI_shift) < RSI_BelowLevel &&
                     iRSI(gRandomSymbol,PERIOD_H1,RSI_Period,RSI_AppliedPrice,RSI_shift) < RSI_BelowLevel &&
                     iRSI(gRandomSymbol,PERIOD_H4,RSI_Period,RSI_AppliedPrice,RSI_shift) < RSI_BelowLevel)
                     gSignalStatus = "RSI_BELOW";



Instead of this two big if else, can i write my code like

void CheckRSIConditions()
  {
   gRSISignal = "NoSignal";
   int countUp = 0, countDown = 0;
   bool conditionsUp[7], conditionsDown[7];
   ENUM_TIMEFRAMES periods[7];
   int count = 0;

   if(PeriodM1)
      periods[count++] = PERIOD_M1;
   if(PeriodM5)
      periods[count++] = PERIOD_M5;
   if(PeriodM15)
      periods[count++] = PERIOD_M15;
   if(PeriodM30)
      periods[count++] = PERIOD_M30;
   if(PeriodH1)
      periods[count++] = PERIOD_H1;
   if(PeriodH4)
      periods[count++] = PERIOD_H4;
   if(PeriodD1)
      periods[count++] = PERIOD_D1;

   for(int i = 0; i < count; i++)
     {
      double rsiValue = iRSI(gRandomSymbol, periods[i], RSI_Period, RSI_AppliedPrice, RSI_shift);
      conditionsUp[i] = (rsiValue > RSI_UpLevel);
      conditionsDown[i] = (rsiValue < RSI_BelowLevel);
     }

   bool allTrueUp = (count > 0);
   for(int j = 0; j < count; j++)
     {
      if(!conditionsUp[j])
        {
         allTrueUp = false;
         break;
        }
     }

   if(allTrueUp)
      gRSISignal = "UP";

   bool allTrueDown = (count > 0);
   for(int k = 0; k < count; k++)
     {
      if(!conditionsDown[k])
        {
         allTrueDown = false;
         break;
        }
     }

   if(allTrueDown)
      gRSISignal = "BELOW";
  }
 

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

 
William Roeder #:

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

Ok, So my code is current to check all timeframe. i just have to add some error handling.