GG-RSI-CCI
Download scriptThis tool is designed to assist traders in identifying market trends by combining two well-known technical analysis methods: the Relative Strength Index (RSI) and the Commodity Channel Index (CCI). Instead of looking at these indicators in isolation, the script merges them to create a more cohesive visual signal on your trading chart.
How the Logic Works
The script processes market data through a multi-layered calculation to determine whether the current price momentum is bullish (upward), bearish (downward), or neutral. Here is the step-by-step breakdown of that process:
1. Data Collection First, the tool looks at the closing prices of the currency pair or asset you are viewing. It pulls two specific types of data based on a user-defined timeframe:
- RSI: Measures the speed and change of price movements to identify overbought or oversold conditions.
- CCI: Measures where the current price is relative to its average price over a specific period.
2. Smoothing the Data Raw data from RSI and CCI can often be "noisy" or jump around too quickly to provide clear signals. To fix this, the script applies two different sets of moving averages to both indicators simultaneously. By using different periods for these averages, the tool creates two distinct "smoothed" lines for each indicator.
3. Trend Comparison (The Signal) The core logic happens by comparing these smoothed lines against one another. The script looks for a consensus between both the RSI and the CCI:
- Bullish Signal: If the shorter-term average is higher than the longer-term average for both the RSI and the CCI, the script recognizes strong upward momentum.
- Bearish Signal: If the shorter-term average is lower than the longer-term average for both the RSI and the CCI, the script recognizes strong downward momentum.
- Neutral Signal: If the indicators do not agree (for example, if one shows strength while the other shows weakness), the tool considers the market to be in a "flat" or indecisive state.
Visual Representation
The result of this logic is displayed as a histogram in a separate window on your chart:
- Upper Bars: Indicate a confirmed bullish trend where both indicators agree on upward momentum.
- Lower Bars: Indicate a confirmed bearish trend where both indicators agree on downward momentum.
- Middle Bars: Indicate a neutral zone where there is no clear consensus between the two indicators, suggesting you should exercise caution or wait for a clearer signal.
//+------------------------------------------------------------------+
//| GG-RSI-CCI.mq4 |
//| Copyright © 2009, GGekko |
//| http://www.fx-ggekko.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, GGekko"
#property link "http://www.fx-ggekko.com"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 YellowGreen
#property indicator_color2 Gold
#property indicator_color3 OrangeRed
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_minimum 0
#property indicator_maximum 1.5
//---- indicator parameters
extern string __Copyright__ = "www.fx-ggekko.com";
extern int Avg_Period1 = 8;
extern int Avg_Period2 = 14;
extern int Ind_Period = 20;
//---- indicator buffers
double BufferUp[];
double BufferFlat[];
double BufferDown[];
double ind1[];
double ind2[];
double ind3[];
double ind4[];
double ind5[];
double ind6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
IndicatorBuffers(5);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
//---- indicator buffers mapping
SetIndexBuffer(0,BufferUp);
SetIndexBuffer(1,BufferFlat);
SetIndexBuffer(2,BufferDown);
SetIndexBuffer(3,ind1);
SetIndexBuffer(4,ind2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("GG-RSI-CCI ("+Avg_Period1+","+Avg_Period2+","+Ind_Period+") * www.fx-ggekko.com * ");
//---- initialization done
return(0);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
ArrayResize(ind3,limit);
ArrayResize(ind4,limit);
ArrayResize(ind5,limit);
ArrayResize(ind6,limit);
for(int i=0; i<limit; i++)
ind1[i]=iRSI(NULL,0,Ind_Period,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
ind2[i]=iCCI(NULL,0,Ind_Period,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
ind3[i]=iMAOnArray(ind1,0,Avg_Period1,0,MODE_SMMA,i);
for(i=0; i<limit; i++)
ind4[i]=iMAOnArray(ind1,0,Avg_Period2,0,MODE_SMMA,i);
for(i=0; i<limit; i++)
ind5[i]=iMAOnArray(ind2,0,Avg_Period1,0,MODE_SMMA,i);
for(i=0; i<limit; i++)
ind6[i]=iMAOnArray(ind2,0,Avg_Period2,0,MODE_SMMA,i);
for(i=0; i<limit; i++)
{
if(ind3[i]>ind4[i] && ind5[i]>ind6[i])
{
BufferUp[i]=1;
BufferFlat[i]=EMPTY_VALUE;
BufferDown[i]=EMPTY_VALUE;
}
else if(ind3[i]<ind4[i] && ind5[i]<ind6[i])
{
BufferUp[i]=EMPTY_VALUE;
BufferFlat[i]=EMPTY_VALUE;
BufferDown[i]=1;
}
else
{
BufferUp[i]=EMPTY_VALUE;
BufferFlat[i]=1;
BufferDown[i]=EMPTY_VALUE;
}
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments