Figurelli RSI Auto
Download scriptThis script is a specialized technical analysis tool designed to measure the momentum and strength of price movements. It builds upon the logic of the Relative Strength Index (RSI) but incorporates an automated adjustment system to help keep the visual data within a readable range.
Core Mechanism: Price Momentum Tracking
The underlying logic works by analyzing the differences between consecutive closing prices over a specific timeframe (defined by the "period" setting).
- Positive Movement: When the price rises from one candle to the next, the script tracks the amount of that gain.
- Negative Movement: When the price falls, the script tracks the magnitude of that loss.
By separating these two types of movements, the tool calculates a ratio of "upward strength" versus "downward strength." This helps traders identify whether a market move is being driven more by buyers or sellers.
The "Auto" Adjustment Logic
What distinguishes this specific version from a standard RSI is its dynamic scaling logic. The script performs three main actions to ensure the data remains useful for visual analysis:
- Smoothing and Weighting: It uses a "gain" factor to multiply the resulting indicator value. This amplifies the movement, making it easier to see trends that might otherwise appear flat on a standard chart.
- Boundary Protection (Capping): The script constantly monitors the output values. If the calculated momentum exceeds the standard boundaries (specifically moving beyond the +/- 50 threshold relative to the center line), the script "caps" the value. This prevents the indicator from shooting off the screen and becoming unreadable during extreme market volatility.
- Dynamic Sensitivity Adjustment: When the momentum hits these boundaries, the script automatically reduces the "gain" factor slightly. By lowering this multiplier in real-time, the tool tries to "re-center" itself, allowing it to continue providing meaningful data even during very strong, sustained trends without losing its visual scale.
Summary for the User
In simple terms, this tool acts as a "smart" momentum meter. It measures how hard the market is pushing in one direction compared to another. If the market pushes too hard for the indicator to keep up visually, the script automatically dials back its own sensitivity to ensure the line stays centered and easy to read on your screen at all times.
//+------------------------------------------------------------------+
//| Figurelli RSI Auto.mq4 |
//| Copyright © 2011, Rogerio Figurelli |
//| http://www.trajecta.com.br |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Rogerio Figurelli"
#property link "http://www.trajecta.com.br"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_level1 70
#property indicator_level2 50
#property indicator_level3 30
//---- input parameters
extern int period=120;
//---- global vars
static double gain;
static double buffer_indicator[];
static double buffer_positive[];
static double buffer_negative[];
static string name;
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int init() {
gain=period/5;
if (gain<1) gain=1;
IndicatorBuffers(3);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,buffer_indicator);
name="Figurelli RSI Auto ("+period+","+gain+")";
IndicatorShortName(name);
SetIndexLabel(0,name);
SetIndexDrawBegin(0,period);
SetIndexBuffer(1,buffer_positive);
SetIndexBuffer(2,buffer_negative);
return(0);
}
//+------------------------------------------------------------------+
//| Figurelli Relative Strength Index |
//+------------------------------------------------------------------+
int start() {
int i,j;
int counted_bars=IndicatorCounted();
double diff;
double negative,n;
double positive,p;
bool gainOK;
if (Bars<=period) return(0);
if (counted_bars<1) {
for (i=1;i<=period;i++)
buffer_indicator[Bars-i]=0;
}
i=Bars-period-1;
if (counted_bars>=period)
i=Bars-counted_bars-1;
while (i>=0) {
n=0;
p=0;
if (i==(Bars-period-1)) {
j=Bars-2;
while (j>=i) {
diff=Close[j]-Close[j+1];
if (diff>0)
p+=diff;
else
n-=diff;
j--;
}
positive=p/period;
negative=n/period;
}
else {
diff=Close[i]-Close[i+1];
if (diff>0)
p=diff;
else
n=-diff;
positive=(buffer_positive[i+1]*(period-1)+p)/period;
negative=(buffer_negative[i+1]*(period-1)+n)/period;
}
buffer_positive[i]=positive;
buffer_negative[i]=negative;
if (negative==0)
buffer_indicator[i]=0;
else
buffer_indicator[i]=100-100/(1+positive/negative);
buffer_indicator[i]-=50;
buffer_indicator[i]*=gain;
if (buffer_indicator[i]<-50) {
buffer_indicator[i]=-50;
gain-=0.1;
if (gain<1) gain=1;
name="Figurelli RSI Auto ("+period+","+gain+")";
IndicatorShortName(name);
SetIndexLabel(0,name);
}
if (buffer_indicator[i]>50) {
buffer_indicator[i]=50;
gain-=0.1;
if (gain<1) gain=1;
name="Figurelli RSI Auto ("+period+","+gain+")";
IndicatorShortName(name);
SetIndexLabel(0,name);
}
buffer_indicator[i]+=50;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments