RSI BAR CHARTv2
Download scriptOverview
The GH-RSI Bar Chart is a visual trading tool designed to provide a more dynamic and readable representation of the Relative Strength Index (RSI). While a standard RSI usually appears as a single moving line, this script transforms that data into a bar-like structure, making it easier for traders to visualize price action and momentum trends within the indicator window.
How the Logic Works
The script functions by analyzing four specific data points from the RSI calculation for every historical candle: the Open, High, Low, and Close values.
1. Data Processing For every bar on your chart, the script calculates these four RSI values. It then compares the "Open" and "Close" prices of the RSI to determine the direction of the movement:
- If the RSI closed higher than it opened, the script identifies this as upward momentum.
- If the RSI closed lower than it opened, it identifies this as downward momentum.
2. Visual Representation Instead of just plotting a line, the script draws individual trend lines to mimic the appearance of a bar chart:
- The Body: The script draws a thicker line representing the range between the RSI "Open" and "Close" prices. This helps you see the core strength of the movement during that specific period.
- The Wick (Shadow): It then draws a thinner line extending to the RSI "High" and "Low" points. This shows you the total volatility or the extreme reach of the price movement.
3. Color Coding To make these trends instantly recognizable, the script applies dynamic coloring:
- Directional Colors: By default, it uses different colors (typically Lime for up and White/Red for down) to highlight whether the momentum is positive or negative.
- Uniform Mode: There is also an option to force a single color if you prefer to focus purely on the shape of the bars rather than their direction.
Important Usage Note
Because this script calculates values based on current price action, it is designed to provide the most accurate visual "snapshot" once a candle has finished forming (closed). During live trading, the high and low values may shift as the price moves; therefore, the final shape of the bar is finalized at the moment the candle closes.
//+------------------------------------------------------------------+
//| GH-RSI BAR CHART |
//| Copyright c 2009, Godfreyh@gmail.com |
//| forex-factory.com |
//| REFRESH ISSUES FIXED BY Obaidah |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
//| take care that this indicator doesnt resize the trendline in the
//|indicator window, for that reason,if you run that in real time
//|(before the bar close), it will give you different high/low than
//|when you run it after the bar close
//+-------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 4
extern color OneColor = Blue,
UpColor = Lime,
DnColor = White;
extern bool UseOneColor = false;
extern int RSI_Period =14;
//----
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
//---- indicators
IndicatorBuffers(4);
// SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0, ExtMapBuffer1);//high/low buffer
// SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1, ExtMapBuffer2); //high/low buffer
// SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2, ExtMapBuffer3); //open buffer
// SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3, ExtMapBuffer4);// close buffer
//----
//---- indicator buffers mapping
IndicatorShortName("GH RSI BAR CHARTv2");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
ObjectsDeleteAll();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
// take care that this indicator doesnt resize the trendline in the indicator window, for that reason,
//if you run that in real time (before the bar close), it will give you different high/low than when you run it
//after the bar close
double rsiOpen, rsiHigh, rsiLow, rsiClose;
if(Bars<=10) return(0);
ExtCountedBars=IndicatorCounted();
//---- check for isible errors
if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
if (ExtCountedBars>0) ExtCountedBars--;
int i=Bars-ExtCountedBars-1; // when Bars increases by 1 i will be 1, in the next time extcountedbars will
//increase by one and i will be equal to 0, when a new bar comes the value of Bars will increase by one and so,
//the value of i will be 1 again
while(i>=0)
{
rsiOpen= iRSI(NULL,0,RSI_Period,PRICE_OPEN,i);
rsiClose=iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i);
rsiHigh= iRSI(NULL,0,RSI_Period,PRICE_HIGH,i);
rsiLow= iRSI(NULL,0,RSI_Period,PRICE_LOW,i);
if (rsiOpen<rsiClose)
{
ExtMapBuffer1[i]=rsiLow;
ExtMapBuffer2[i]=rsiHigh;
}
else
{
ExtMapBuffer1[i]=rsiHigh;
ExtMapBuffer2[i]=rsiLow;
}
ExtMapBuffer3[i]=rsiOpen;
ExtMapBuffer4[i]=rsiClose;
if(UseOneColor)// double rsiOpen, rsiHigh, rsiLow, rsiClose;
{
drawLine("BB"+Time[i],Time[i],rsiOpen,rsiClose,3,OneColor); // Time[i] instead of i, for, during the real time
//calculating, the value of i will range between 1 and 0, so you'll have the same name for each new bar
//.... in the draw function it will skipe drawing new one because of the first if statement
//So we had to assine something uniqe to the name of the line, which is the time of that bar.
drawLine("SB"+Time[i],Time[i],rsiHigh,rsiLow,1,OneColor);
}
else
{
if(rsiClose<rsiOpen)
{
drawLine("BB"+Time[i],Time[i],rsiOpen,rsiClose,2,DnColor);
drawLine("SB"+Time[i],Time[i],rsiHigh,rsiLow,1,DnColor);
}
else
{
drawLine("BB"+Time[i],Time[i],rsiOpen,rsiClose,2,UpColor);
drawLine("SB"+Time[i],Time[i],rsiHigh,rsiLow,1,UpColor);
}
}
i--;
}
//----
return(0);
}
//----
void drawLine(string name,datetime time, double pfrom, double pto, int width,color Col)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_TREND, WindowFind("GH RSI BAR CHARTv2"), time, pfrom,time,pto);
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,width);
ObjectSet(name,OBJPROP_RAY,0);
}
else
{
ObjectDelete(name);
ObjectCreate(name, OBJ_TREND, WindowFind("GH RSI BAR CHARTv2"), time, pfrom,time,pto);
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,width);
ObjectSet(name,OBJPROP_RAY,0);
}
}
//+------------------------------------------------------------------+
Comments