stochRSI
Download scriptThis tool is a custom technical analysis indicator designed to help traders identify momentum and potential overbought or oversold conditions in the financial markets. It functions by combining two well-known mathematical models—the Relative Strength Index (RSI) and the Stochastic Oscillator—into a single, more sensitive visual tool.
How the Logic Works
The script operates through a multi-layered calculation process to smooth out market "noise" and highlight significant price movements:
1. The Foundation: RSI Calculation First, the tool looks at the Relative Strength Index (RSI). This is a standard measurement that evaluates the speed and change of price movements. Instead of looking at raw prices, it focuses on how strongly the market is moving in one direction compared to the other over a specific timeframe.
2. The Momentum Layer: Stochastic Mapping Rather than plotting the RSI directly, this script takes the RSI values and applies "Stochastic" logic to them. It scans back through a set number of previous periods to identify the highest and lowest RSI values reached during that time. By comparing the current RSI value against these extremes, the tool determines where the current momentum sits relative to its recent range.
- If the current momentum is near the "highest" historical point, it suggests the market might be reaching an upper limit (overbought).
- If it is near the "lowest" historical point, it suggests the market might be hitting a floor (oversold).
3. The Smoothing Layer: Signal Line To prevent the data from jumping around too erratically, the script calculates a second line known as a "Signal" line. This is created by taking an average of previous momentum readings over a short period.
Visual Output and Interpretation
The indicator produces two distinct lines on a separate window below your main price chart:
- The Main Line (Warrior_Of_Jihad): This represents the primary Stochastic RSI value. It fluctuates between 0 and 100, showing the current intensity of the momentum relative to its recent history.
- The Signal Line: This acts as a moving average for the main line. Traders often look for "crosses" between these two lines—where the Main Line moves above or below the Signal Line—as potential triggers for entering or exiting a trade.
By combining these three steps, the script provides a refined view of market strength, aiming to give traders a clearer picture of whether a trend is gaining steam or starting to exhaust itself.
//+------------------------------------------------------------------+
//| Stochastic RSI.mq4 |
//| tonyc2a@yahoo.com |
//| |
//+------------------------------------------------------------------+
#property copyright "tonyc2a@yahoo.com"
#property link ""
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_minimum -5
#property indicator_maximum 105
#property indicator_color1 Black
#property indicator_color2 Blue
//---- input parameters
extern int RSI_Periods=14;
extern int Percent_K=14;
extern int Percent_D=9;
extern int NumOfBars=0;
//---- buffers
double Buffer1[];
double Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(0,Buffer1);
SetIndexLabel(0,"Warrior_Of_Jihad");
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(1,Buffer2);
SetIndexLabel(1,"Signal");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double Current_RSI,Lowest_RSI,Highest_RSI,sum_K;
//---- TODO: add your code here
if(NumOfBars==0)NumOfBars=Bars;
for(int i=NumOfBars-MathMax(RSI_Periods,Percent_K)-1;i>=0;i--){
Current_RSI=iRSI(NULL,0,RSI_Periods,PRICE_TYPICAL,i);
Highest_RSI=Current_RSI;
Lowest_RSI=Current_RSI;
for(int x=0;x<=Percent_K;x++){
Lowest_RSI=MathMin(Lowest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_TYPICAL,i+x));
Highest_RSI=MathMax(Highest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_TYPICAL,i+x));
}
sum_K=0;
for(x=0;x<=Percent_D;x++) sum_K=sum_K+Buffer1[i+x];
Buffer1[i]=((Current_RSI-Lowest_RSI)/(Highest_RSI-Lowest_RSI))*100;
Buffer2[i]=sum_K/Percent_D;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments