//+------------------------------------------------------------------+
//| WickAtlas RSI Regime                                             |
//| Version 1.0.0 - 2026-07-27                                      |
//| MIT License - Copyright (c) 2026 WickAtlas                       |
//| Educational analytical tool. No orders, DLLs or network access.  |
//+------------------------------------------------------------------+
#property copyright "WickAtlas"
#property link      "https://wickatlas.com/downloads"
#property version   "1.00"
#property description "RSI with 40/50/60 research regime levels."
#property description "This indicator does not place trades or promise signals."
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_plots   1

#property indicator_label1  "RSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrMediumSeaGreen
#property indicator_width1  2

#property indicator_level1  40.0
#property indicator_level2  50.0
#property indicator_level3  60.0
#property indicator_levelcolor clrSlateGray
#property indicator_levelstyle STYLE_DOT

input int                InpRSIPeriod     = 14;
input ENUM_APPLIED_PRICE InpAppliedPrice  = PRICE_CLOSE;

double RSIBuffer[];
int RSIHandle=INVALID_HANDLE;

int OnInit()
{
   if(InpRSIPeriod<2)
      return(INIT_PARAMETERS_INCORRECT);

   SetIndexBuffer(0,RSIBuffer,INDICATOR_DATA);
   ArraySetAsSeries(RSIBuffer,true);

   RSIHandle=iRSI(_Symbol,_Period,InpRSIPeriod,InpAppliedPrice);
   if(RSIHandle==INVALID_HANDLE)
      return(INIT_FAILED);

   IndicatorSetString(INDICATOR_SHORTNAME,
      "WickAtlas RSI Regime ("+(string)InpRSIPeriod+")");
   IndicatorSetInteger(INDICATOR_DIGITS,2);
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
   if(RSIHandle!=INVALID_HANDLE)
      IndicatorRelease(RSIHandle);
}

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(rates_total<InpRSIPeriod)
      return(0);

   int count=(prev_calculated==0) ? rates_total : rates_total-prev_calculated+1;
   if(count>rates_total)
      count=rates_total;

   if(CopyBuffer(RSIHandle,0,0,count,RSIBuffer)<=0)
      return(prev_calculated);

   return(rates_total);
}

