• Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)
General chit-chat
Help Users
  • No one is chatting at the moment.

      Divergent RSI code mql4

      rickyandreas290292

      New Member
      Credits
      0
      // Input parameters
      input int period = 14; // RSI period
      input double deviation = 0.0001; // Deviation threshold for divergence detection

      // Function to check for bullish divergence
      bool isBullishDivergence(int bar)
      {
      double rsiValue = iRSI(NULL, 0, period, PRICE_CLOSE, bar);
      double priceValue = Close[bar];
      double rsiPrev = iRSI(NULL, 0, period, PRICE_CLOSE, bar + 1);
      double pricePrev = Close[bar + 1];
      double rsiPrevPrev = iRSI(NULL, 0, period, PRICE_CLOSE, bar + 2);
      double pricePrevPrev = Close[bar + 2];

      if (rsiValue > rsiPrev && rsiPrev < rsiPrevPrev && priceValue > pricePrev && pricePrev < pricePrevPrev)
      {
      double rsiDeviation = MathAbs(rsiValue - rsiPrev);
      double priceDeviation = MathAbs(priceValue - pricePrev);
      if (rsiDeviation > deviation && priceDeviation < deviation)
      {
      return true;
      }
      }

      return false;
      }

      // Function to check for bearish divergence
      bool isBearishDivergence(int bar)
      {
      double rsiValue = iRSI(NULL, 0, period, PRICE_CLOSE, bar);
      double priceValue = Close[bar];
      double rsiPrev = iRSI(NULL, 0, period, PRICE_CLOSE, bar + 1);
      double pricePrev = Close[bar + 1];
      double rsiPrevPrev = iRSI(NULL, 0, period, PRICE_CLOSE, bar + 2);
      double pricePrevPrev = Close[bar + 2];

      if (rsiValue < rsiPrev && rsiPrev > rsiPrevPrev && priceValue < pricePrev && pricePrev > pricePrevPrev)
      {
      double rsiDeviation = MathAbs(rsiValue - rsiPrev);
      double priceDeviation = MathAbs(priceValue - pricePrev);
      if (rsiDeviation > deviation && priceDeviation < deviation)
      {
      return true;
      }
      }

      return false;
      }

      // OnTick function
      void OnTick()
      {
      int startBar = 2; // Start bar index for divergence checking
      int endBar = Bars - 1; // End bar index

      for (int bar = startBar; bar <= endBar; bar++)
      {
      if (isBullishDivergence(bar))
      {
      // Bullish divergence detected
      // Perform necessary actions
      Print("Bullish Divergence at Bar ", bar);
      }

      if (isBearishDivergence(bar))
      {
      // Bearish divergence detected
      // Perform necessary actions
      Print("Bearish Divergence at Bar ", bar);
      }
      }
      }
       
      This is my review for this thread:
      Strategi pengelolaan RSI yang bagus.
      Cukup bagus untuk EA yang dijalankan pada XAUUSD.
      Sayangnya saya belum berhasil menerapkan strategi ini pada forex pair (GBP, EUR, JPY, CHF, AUD, dll.)

      Terima kasih sharingnya.
       
      Back
      Top