RSI divergence/reversal logic

 

Hi! I wanted to ask if someone can 'spot' me and double check if my logic is correct with regards to using a RSI to spot a market reversal by means of a using a 1minute RSI with a 14 period value. Is there any room for improvement for better accuracy?

int OnInit()
  {
   RSIOneMinute = iRSI(_Symbol,PERIOD_M1,14,PRICE_CLOSE);

   return(INIT_SUCCEEDED);
  }
   if(CopyBuffer(RSIOneMinute, 0, 0, 8, RSI_MainOneMinute) < 8)
     {
      Print("Failed to read RSI indicator buffer");
      return;
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(RSI_MainOneMinute[0] < 70 && RSI_MainOneMinute[1] > 70 && RSI_MainOneMinute[0] < RSI_MainOneMinute[1])
     {
      RSIResultOne = -1;
     }
   else
      if(RSI_MainOneMinute[0] > 30 && RSI_MainOneMinute[1] < 30 && RSI_MainOneMinute[0] > RSI_MainOneMinute[1])
        {
         RSIResultOne = 1;
        }
   OpenPriceOneMinute = iOpen(_Symbol,PERIOD_M1,0);
   double ClosePriceOneMinute = iClose(_Symbol,PERIOD_M1,1);
   double HighPriceOneMinute = iHigh(_Symbol,PERIOD_M1,1);
   double HighPriceOneMinuteTwoBar = iHigh(_Symbol,PERIOD_M1,2);
   double LowPriceOneMinute = iLow(_Symbol,PERIOD_M1,1);
   double LowPriceOneMinuteTwoBar = iLow(_Symbol,PERIOD_M1,2);

   OpenPriceTwoMinutes = iOpen(_Symbol,PERIOD_M2,0);
   double ClosePriceTwoMinutes = iClose(_Symbol,PERIOD_M2,1);
   double HighPriceTwoMinutes = iHigh(_Symbol,PERIOD_M2,1);
   double LowPriceTwoMinutes = iLow(_Symbol,PERIOD_M2,1);

   OpenPriceThreeMinutes = iOpen(_Symbol,PERIOD_M3,0);
   double ClosePriceThreeMinutes = iClose(_Symbol,PERIOD_M3,1);
   double HighPriceThreeMinutes = iHigh(_Symbol,PERIOD_M3,1);
   double LowPriceThreeMinutes = iLow(_Symbol,PERIOD_M3,1);

   OpenPriceFourMinutes = iOpen(_Symbol,PERIOD_M4,0);
   double ClosePriceFourMinutes = iClose(_Symbol,PERIOD_M4,1);
   double HighPriceFourMinutes = iHigh(_Symbol,PERIOD_M4,1);
   double LowPriceFourMinutes = iLow(_Symbol,PERIOD_M4,1);

   OpenPriceFiveMinutes = iOpen(_Symbol,PERIOD_M5,0);
   double ClosePriceFiveMinutes = iClose(_Symbol,PERIOD_M5,1);
   double HighPriceFiveMinutes = iHigh(_Symbol,PERIOD_M5,1);
   double LowPriceFiveMinutes = iLow(_Symbol,PERIOD_M5,1);

   OpenPriceSixMinutes = iOpen(_Symbol,PERIOD_M6,0);
   double ClosePriceSixMinutes = iClose(_Symbol,PERIOD_M6,1);
   double HighPriceSixMinutes = iHigh(_Symbol,PERIOD_M6,1);
   double LowPriceSixMinutes = iLow(_Symbol,PERIOD_M6,1);

   OpenPriceTenMinutes = iOpen(_Symbol,PERIOD_M10,0);
   double ClosePriceTenMinutes = iClose(_Symbol,PERIOD_M10,1);
   double HighPriceTenMinutes = iHigh(_Symbol,PERIOD_M10,1);
   double LowPriceTenMinutes = iLow(_Symbol,PERIOD_M10,1);

   OpenPriceTwelveMinutes = iOpen(_Symbol,PERIOD_M12,0);
   double ClosePriceTwelveMinutes = iClose(_Symbol,PERIOD_M12,1);
   double HighPriceTwelveMinutes = iHigh(_Symbol,PERIOD_M12,1);
   double LowPriceTwelveMinutes = iLow(_Symbol,PERIOD_M12,1);

   OpenPriceFifteenMinutes = iOpen(_Symbol,PERIOD_M15,0);
   double ClosePriceFifteenMinutes = iClose(_Symbol,PERIOD_M15,1);
   double HighPriceFifteenMinutes = iHigh(_Symbol,PERIOD_M15,1);
   double LowPriceFifteenMinutes = iLow(_Symbol,PERIOD_M15,1);

   OpenPriceTwentyMinutes = iOpen(_Symbol,PERIOD_M20,0);
   double ClosePriceTwentyMinutes = iClose(_Symbol,PERIOD_M20,1);
   double HighPriceTwentyMinutes = iHigh(_Symbol,PERIOD_M20,1);
   double LowPriceTwentyMinutes = iLow(_Symbol,PERIOD_M20,1);

   OpenPriceThirtyMinutes = iOpen(_Symbol,PERIOD_M30,0);
   double ClosePriceThirtyMinutes = iClose(_Symbol,PERIOD_M30,1);
   double HighPriceThirtyMinutes = iHigh(_Symbol,PERIOD_M30,1);
   double LowPriceThirtyMinutes = iLow(_Symbol,PERIOD_M30,1);

   OpenPriceOneHour = iOpen(_Symbol,PERIOD_H1,0);
   double ClosePriceOneHour = iClose(_Symbol,PERIOD_H1,1);
   double HighPriceOneHour = iHigh(_Symbol,PERIOD_H1,1);
   double LowPriceOneHour = iLow(_Symbol,PERIOD_H1,1);

   OpenPriceTwoHour = iOpen(_Symbol,PERIOD_H2,0);
   double ClosePriceTwoHour = iClose(_Symbol,PERIOD_H2,1);
   double HighPriceTwoHour = iHigh(_Symbol,PERIOD_H2,1);
   double LowPriceTwoHour = iLow(_Symbol,PERIOD_H2,1);

   OpenPriceThreeHour = iOpen(_Symbol,PERIOD_H3,0);
   double ClosePriceThreeHour = iClose(_Symbol,PERIOD_H3,1);
   double HighPriceThreeHour = iHigh(_Symbol,PERIOD_H3,1);
   double LowPriceThreeHour = iLow(_Symbol,PERIOD_H3,1);

   OpenPriceFourHour = iOpen(_Symbol,PERIOD_H4,0);
   double ClosePriceFourHour = iClose(_Symbol,PERIOD_H4,1);
   double HighPriceFourHour = iHigh(_Symbol,PERIOD_H4,1);
   double LowPriceFourHour = iLow(_Symbol,PERIOD_H4,1);

   OpenPriceSixHour = iOpen(_Symbol,PERIOD_H6,0);
   double ClosePriceSixHour = iClose(_Symbol,PERIOD_H6,1);
   double HighPriceSixHour = iHigh(_Symbol,PERIOD_H6,1);
   double LowPriceSixHour = iLow(_Symbol,PERIOD_H6,1);

   OpenPriceEightHour = iOpen(_Symbol,PERIOD_H8,0);
   double ClosePriceEightHour = iClose(_Symbol,PERIOD_H8,1);
   double HighPriceEightHour = iHigh(_Symbol,PERIOD_H8,1);
   double LowPriceEightHour = iLow(_Symbol,PERIOD_H8,1);

   OpenPriceTwelveHour = iOpen(_Symbol,PERIOD_H12,0);
   double ClosePriceTwelveHour = iClose(_Symbol,PERIOD_H12,1);
   double HighPriceTwelveHour = iHigh(_Symbol,PERIOD_H12,1);
   double LowPriceTwelveHour = iLow(_Symbol,PERIOD_H12,1);

   OpenPrice = iOpen(_Symbol,PERIOD_D1,0);
   double ClosePrice = iClose(_Symbol,PERIOD_D1,1);
   double HighPrice = iHigh(_Symbol,PERIOD_D1,1);
   double LowPrice = iLow(_Symbol,PERIOD_D1,1);

   Print("Open Price One Minute: ", OpenPriceOneMinute);

   HigherHigh = HighPriceOneMinute > HighPriceOneMinuteTwoBar;
   LowerLow = LowPriceOneMinute < LowPriceOneMinuteTwoBar;
 
Colin Kimble:

Hi! I wanted to ask if someone can 'spot' me and double check if my logic is correct with regards to using a RSI to spot a market reversal by means of a using a 1minute RSI with a 14 period value. Is there any room for improvement for better accuracy?

   if(structTimeEndSession.day_of_week > 0 && structTimeEndSession.day_of_week < 6)
     {
      if(RSIResultOne == 1 && LowerLow && BuyPrice < OpenPrice && BuyPrice < OpenPriceTwelveHour && BuyPrice < OpenPriceEightHour && BuyPrice < OpenPriceSixHour && BuyPrice < OpenPriceFourHour && BuyPrice < OpenPriceThreeHour && BuyPrice < OpenPriceTwoHour && BuyPrice < OpenPriceOneHour && BuyPrice < OpenPriceThirtyMinutes && BuyPrice < OpenPriceTwentyMinutes && BuyPrice < OpenPriceFifteenMinutes && BuyPrice < OpenPriceTwelveMinutes && BuyPrice < OpenPriceTenMinutes && BuyPrice < OpenPriceSixMinutes && BuyPrice < OpenPriceFiveMinutes && BuyPrice < OpenPriceFourMinutes && BuyPrice < OpenPriceThreeMinutes && BuyPrice < OpenPriceTwoMinutes && BuyPrice < OpenPriceOneMinute)
        {
         static datetime prevTime=0;
         datetime lastTime[1];
         if(CopyTime(_Symbol,PERIOD_D1,0,1,lastTime)==1 && prevTime!=lastTime[0])
           {
            prevTime=lastTime[0];

            trade.SetExpertMagicNumber(MagicNumber);
            double EnterLong = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
            EnterLong = NormalizeDouble(EnterLong,_Digits);
            trade.Buy(Lots,_Symbol,EnterLong,NULL,NULL,"Enter Long");
           }
        }
     }

   if(structTimeEndSession.day_of_week > 0 && structTimeEndSession.day_of_week < 6)
     {
      if(RSIResultOne == -1 && HigherHigh && SellPrice > OpenPrice && SellPrice > OpenPriceTwelveHour && SellPrice > OpenPriceEightHour && SellPrice > OpenPriceSixHour && SellPrice > OpenPriceFourHour && SellPrice > OpenPriceThreeHour && SellPrice > OpenPriceTwoHour && SellPrice > OpenPriceOneHour && SellPrice > OpenPriceThirtyMinutes && SellPrice > OpenPriceTwentyMinutes && SellPrice > OpenPriceFifteenMinutes && SellPrice > OpenPriceTwelveMinutes && SellPrice > OpenPriceTenMinutes && SellPrice > OpenPriceSixMinutes && SellPrice > OpenPriceFiveMinutes && SellPrice > OpenPriceFourMinutes && SellPrice > OpenPriceThreeMinutes && SellPrice > OpenPriceTwoMinutes && SellPrice > OpenPriceOneMinute)
        {
         static datetime prevTime=0;
         datetime lastTime[1];
         if(CopyTime(_Symbol,PERIOD_D1,0,1,lastTime)==1 && prevTime!=lastTime[0])
           {
            prevTime=lastTime[0];
            trade.SetExpertMagicNumber(MagicNumber);
            double EnterShort = SymbolInfoDouble(_Symbol,SYMBOL_BID);
            EnterShort = NormalizeDouble(EnterShort,_Digits);
            trade.Sell(Lots,_Symbol,EnterShort,NULL,NULL,"Enter Short");
           }
        }
     }
  }

I forgot to add this in too, this is where the final conditional would be before submission.

 

It seems you are using MT5. I strongely unrecommend to use iClose, iOpen etc.

Use MqlRates structure and CopyRates command, this will not only make your code more efficient and reliable, but also readable, which at the moment it's very far from...

 
Fabio Cavalloni #:

It seems you are using MT5. I strongely unrecommend to use iClose, iOpen etc.

Use MqlRates structure and CopyRates command, this will not only make your code more efficient and reliable, but also readable, which at the moment it's very far from...

Thanks for the advice. How does functionality differ between Mql rates and the iOpen, iClose, iLow, iHigh functions in terms of efficency?

 
Colin Kimble #:

Thanks for the advice. How does functionality differ between Mql rates and the iOpen, iClose, iLow, iHigh functions in terms of efficency?

https://www.mql5.com/en/forum/451498

Differance between MqlRates and other methods ?
Differance between MqlRates and other methods ?
  • 2023.07.27
  • Ahmed_Fouda
  • www.mql5.com
is there any difference between using MqlRates and using iCLose for example...
 

IYO is the data synchronization issue with iOHLC shit on all time frames or mostly on the smaller, 'more active' time frame ie 1 min, 2 min, 3 min etc?