//+------------------------------------------------------------------+
//|                                  RSI_Divergence_Scanner_MT5.mq5  |
//|                    Copyright 2026, TraderSentiments Quant Team   |
//|                                    https://tradersentiments.com  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, TraderSentiments"
#property link      "https://tradersentiments.com/indicators/mt5/oscillators/rsi-divergence-indicator"
#property version   "2.00"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3

#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrLimeGreen
#property indicator_type3   DRAW_ARROW
#property indicator_color3  clrCrimson

input int      InpRSIPeriod        = 14;          // RSI Period
input bool     InpPushAlerts       = true;        // Mobile Push Alerts

double RSIBuffer[];
double BullishDivBuffer[];
double BearishDivBuffer[];
int    RSIHandle;

int OnInit()
  {
   SetIndexBuffer(0, RSIBuffer, INDICATOR_DATA);
   SetIndexBuffer(1, BullishDivBuffer, INDICATOR_DATA);
   SetIndexBuffer(2, BearishDivBuffer, INDICATOR_DATA);

   RSIHandle = iRSI(_Symbol, _Period, InpRSIPeriod, PRICE_CLOSE);
   IndicatorSetString(INDICATOR_SHORTNAME, "RSI Divergence Scanner MT5");
   return(INIT_SUCCEEDED);
  }

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[])
  {
   if(CopyBuffer(RSIHandle, 0, 0, rates_total, RSIBuffer) <= 0) return(0);
   return(rates_total);
  }
