FX5_SelfAdjustingRSI_v1.0[1]_v1

Download script
Author: FX5
FX5_SelfAdjustingRSI_v1.0[1]_v1

This tool is a sophisticated technical analysis indicator designed to help traders identify "overbought" and "oversold" conditions in the financial markets. While it is based on the standard Relative Strength Index (RSI), it distinguishes itself by being "self-adjusting."

Unlike traditional RSI indicators that use fixed, static horizontal lines to signal entry or exit points, this script dynamically calculates its own boundaries based on current market volatility. This makes it more responsive to different market environments, as it adapts to the unique price swings of any specific asset at any given time.

How the Logic Works

The indicator operates using two primary calculation paths, depending on your preference:

1. The Moving Average Method In this mode, the script calculates a "smoothed" version of the RSI. It then measures how far the current RSI price deviates from that average. By calculating the average of these deviations over a specific period, the tool creates a dynamic range. This helps in identifying when price action is moving significantly further than usual, suggesting an extreme market state.

2. The Standard Deviation Method This is a more statistical approach. The script analyzes the volatility (Standard Deviation) of the RSI values directly. It uses this data to project the upper and lower boundaries. If the market becomes highly volatile, the boundaries widen; if the market stays calm, the boundaries tighten.

Key Features for Traders

  • Dynamic Boundaries: Instead of relying on a generic "70" or "30" level, the indicator draws moving upper and lower borders. These lines expand and contract automatically to reflect real-time market behavior.
  • Visual Clarity: The tool clearly plots the RSI line along with these adjustable boundaries, providing a visual representation of when the market is stretching too far in one direction.
  • Customizable Sensitivity: Users can adjust the period of the RSI and the "deviation" multiplier to fine-tune how aggressively or conservatively the indicator reacts to price movements.

Summary

By automating the calculation of "normal" versus "extreme" price behavior, this script removes much of the guesswork involved in setting manual levels. It provides a more objective way to see when a market move has become overextended relative to its recent history.

Indicators Used
Relative strength indexStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
FX5_SelfAdjustingRSI_v1.0[1]_v1
//+------------------------------------------------------------------+
//|                                         FX5_SelfAdjustingRSI.mq4 |
//|                                                              FX5 |
//|                                                    hazem@uk2.net |
//+------------------------------------------------------------------+
#property copyright "FX5"
#property link      "hazem@uk2.net"
//----
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_maximum 100
#property indicator_buffers 3
#property indicator_level1  20
#property indicator_level2  50
#property indicator_level3  80
//---- input parameters
extern int    rsiPeriod=14;
extern double diviation=2;
extern bool   MA_Method=true;
extern color  rsiColor=Blue;
extern color  overBoughtColor=Red;
extern color  overSoldColor=Green;
//---- buffers
double rsi[];
double upperBorder[];
double lowerBorder[];
double absDiviation[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_LINE, EMPTY, EMPTY, rsiColor);
   SetIndexStyle(1, DRAW_LINE, EMPTY, EMPTY, overBoughtColor);
   SetIndexStyle(2, DRAW_LINE, EMPTY, EMPTY, overSoldColor);
//----   
   SetIndexBuffer(0, rsi);
   SetIndexBuffer(1, upperBorder);
   SetIndexBuffer(2, lowerBorder);
//----   
   SetIndexDrawBegin(0, rsiPeriod);
   SetIndexDrawBegin(1, rsiPeriod * 2);
   SetIndexDrawBegin(2, rsiPeriod * 2);
//----   
   SetIndexLabel(0, "RSI");
   SetIndexLabel(1, "OverBought");
   SetIndexLabel(2, "OverSold");
//----
   IndicatorShortName("FX5_SelfAdjustingRSI( " + rsiPeriod + " )");
   IndicatorBuffers(4);
   SetIndexBuffer(3, absDiviation);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int countedBars=IndicatorCounted();
//----   
   if(MA_Method==true)
      MovingAverageMethod(countedBars);
   else
      StandardDeviationMethod(countedBars);
//----         
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void MovingAverageMethod(int countedBars)
  {
   if(countedBars < 0)
      countedBars=0;
//----      
   for(int i=Bars - countedBars; i>=0; i--)
     {
      rsi[i]=iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, i);
      double smoothedRSI=GetSmoothedRSI(i);
      absDiviation[i]=MathAbs(rsi[i] - smoothedRSI);
      double kDiviation=diviation * GetAbsDiviationAverage(i);
      upperBorder[i]=50 + kDiviation;
      lowerBorder[i]=50 - kDiviation;
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void StandardDeviationMethod(int countedBars)
  {
   if(countedBars < 0)
      countedBars=0;
//----
   for(int i=Bars - countedBars; i>=0; i--)
     {
      rsi[i]=iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, i);
      double rsiDiviation=iStdDevOnArray(rsi, 0, rsiPeriod, 0,
                                           MODE_SMA, i);
      double kDiviation=diviation * rsiDiviation;
      upperBorder[i]=50 + kDiviation;
      lowerBorder[i]=50 - kDiviation;
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetSmoothedRSI(int shift)
  {
   double sum=0;
   for(int i=shift; i < shift + rsiPeriod; i++)
     {
      sum+=rsi[i];
     }
   return(sum/rsiPeriod);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetAbsDiviationAverage(int shift)
  {
   double sum=0;
   for(int i=shift; i < shift + rsiPeriod; i++)
     {
      sum+=absDiviation[i];
     }
   return(sum/rsiPeriod);
  }
//+------------------------------------------------------------------+

Comments