RSI_C
Download scriptThis technical tool is designed to provide a visual analysis of market momentum by identifying specific overbought and oversold conditions. It builds upon the Relative Strength Index (RSI), a standard financial oscillator, but adds a unique layer of logic to highlight sustained price movements rather than just momentary fluctuations.
Core Functionality
The script calculates the RSI based on user-defined parameters, such as the look-back period and the specific price type (e.g., closing price or high/low range). It maps these values onto a dedicated window below the main price chart, allowing traders to see whether an asset is potentially overextended in either direction.
Dynamic Threshold Monitoring
Unlike a standard RSI indicator that only shows a continuous line, this script introduces "tracking logic" for two specific zones:
- Overbought Zone: Triggered when the RSI exceeds a high threshold (default is 70).
- Oversold Zone: Triggered when the RSI falls below a low threshold (calculated as the inverse of your high level, e.g., 30).
Visual Logic and Signal Processing
The primary logic of this script is to "capture" and display data points only when they interact with these critical thresholds. It performs the following actions:
- Momentum Capture: Instead of showing the full RSI line at all times, the script identifies instances where the indicator enters the overbought or oversold territory.
- Consecutive Point Mapping: When the RSI crosses into these zones, the logic looks back at the preceding candles. It essentially "anchors" the data points on the chart to show a clear visual representation of how long the asset has remained in an extreme state.
- Color-Coded Filtering: By separating these points into different buffers, the script allows for distinct visual styles. This helps distinguish between "High Pressure" (overbought) and "Low Pressure" (oversold) at a single glance, filtering out the "noise" of the middle range where the market is in a neutral state.
Summary for the User
This tool acts as a filter. It ignores the standard movement of the RSI when the market is behaving normally and only highlights specific peaks and troughs. By doing so, it helps a visitor quickly identify periods of extreme price exhaustion, making it easier to spot potential reversal points or trend continuations without being distracted by constant fluctuations in the middle of the trading range.
//+------------------------------------------------------------------+
//| RSI_C.mq4 |
//| * |
//| * |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link "for-good-letters@yandex.ru"
#property indicator_separate_window
#property indicator_maximum 100
#property indicator_minimum 0
#property indicator_buffers 3
#property indicator_color1 Khaki
#property indicator_color2 DeepSkyBlue
#property indicator_color3 Red
//---- input parameters
extern int RSIPeriod = 14; // Ïåðèîä RSI
extern int RSIPrice = 0; // Öåíà RSI: 0-Close, 1-Open, 2-High, 3-Low, 4-Median, 5-Typical, 6-Weighted
extern int RSILevel = 70; // Âåðõíèé óðîâåíü RSI, íèæíèé ðàâåí 100-RSILevel
//---- buffers
double rsi[];
double up[];
double lo[];
int LoLevel;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,rsi);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,up);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,lo);
LoLevel=100-RSILevel;
SetLevelValue(0,RSILevel);
SetLevelValue(1,LoLevel);
SetIndexLabel(0,"RSI");
SetIndexLabel(1,"");
SetIndexLabel(2,"");
SetIndexDrawBegin(0,RSIPeriod+1);
SetIndexDrawBegin(1,RSIPeriod+1);
SetIndexDrawBegin(2,RSIPeriod+1);
IndicatorShortName("RSI");
IndicatorDigits(2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit=Bars-IndicatorCounted();
for(int i=limit-1;i>=0;i--){
up[i]=EMPTY_VALUE;
lo[i]=EMPTY_VALUE;
up[i+1]=EMPTY_VALUE;
lo[i+1]=EMPTY_VALUE;
rsi[i]=iRSI(NULL,0,RSIPeriod,RSIPrice,i);
if(rsi[i]>=RSILevel){
up[i]=rsi[i];
up[i+1]=rsi[i+1];
}
else{
if(rsi[i+1]>=RSILevel){
up[i]=rsi[i];
up[i+1]=rsi[i+1];
}
}
if(rsi[i+1]>=RSILevel){
up[i+1]=rsi[i+1];
up[i+2]=rsi[i+2];
}
else{
if(rsi[i+2]>=RSILevel){
up[i+1]=rsi[i+1];
up[i+2]=rsi[i+2];
}
}
if(rsi[i]<=LoLevel){
lo[i]=rsi[i];
lo[i+1]=rsi[i+1];
}
else{
if(rsi[i+1]<=LoLevel){
lo[i]=rsi[i];
lo[i+1]=rsi[i+1];
}
}
if(rsi[i+1]<=LoLevel){
lo[i+1]=rsi[i+1];
lo[i+2]=rsi[i+2];
}
else{
if(rsi[i+2]<=LoLevel){
lo[i+1]=rsi[i+1];
lo[i+2]=rsi[i+2];
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments