CCI CustomCandles_v1
Download scriptThis tool is designed to enhance the visual representation of your trading charts by layering custom colored candles over existing price data. It acts as a visual filter, helping traders quickly identify specific market conditions—specifically areas of extreme momentum—without cluttering the screen with complex lines or extra windows.
How the Logic Works
The script functions by monitoring a technical indicator known as the Commodity Channel Index (CCI). The CCI is used to measure where the current price sits in relation to its recent average, helping to identify if a market is "overextended."
The tool applies the following logic to your chart:
- Monitoring Market Extremes: The script constantly scans the price history based on a user-defined period (defaulting to 25). It looks for two specific thresholds: an "Overbought" level and an "Oversold" level.
- Dynamic Visual Signaling: Instead of just providing a numerical value, the tool changes the visual appearance of the candles on your chart based on where the CCI falls:
- Overbought Signals: When the market momentum reaches a predefined high point (the Overbought zone), the script highlights the price bars in one color (Green).
- Oversold Signals: When the market momentum drops to a predefined low point (the Oversold zone), the script highlights the price bars in a different color (Red).
- Visual Distinction: The script differentiates between the "wick" (the thin line of the candle) and the "body" (the thick center part). It applies these colors specifically to these components so that you can clearly see the intensity of the price action at a glance.
Summary for the Trader
Essentially, this script serves as a "heat map" for price momentum. It automatically paints your chart to highlight sections where the market might be reaching an exhaustion point. By looking at the colors of the candles, you can instantly identify periods where the asset is significantly overextended in either direction, allowing for faster visual analysis of potential reversal zones.
//+------------------------------------------------------------------+
//| CCI CustomCandles.mq4 |
//| modified by cja |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Christof Risch (iya)"
#property link "http://www.forexfactory.com/showthread.php?t=13321"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green//wick
#property indicator_color2 Red//wick
#property indicator_color3 Green//candle
#property indicator_color4 Red//candle
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
//---- stoch settings
extern int CCI_Period = 25;
extern int CCI_Price = 0;
extern int Overbought = 480;
extern int Oversold = -480;
//---- input parameters
extern int BarWidth = 1,
CandleWidth = 3;
//---- buffers
double Bar1[],
Bar2[],
Candle1[],
Candle2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorShortName("CCI Candles:("+ CCI_Period+")");
IndicatorBuffers(4);
SetIndexBuffer(0,Bar1);
SetIndexBuffer(1,Bar2);
SetIndexBuffer(2,Candle1);
SetIndexBuffer(3,Candle2);
SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth);
SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth);
SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth);
SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth);
return(0);
}
//+------------------------------------------------------------------+
double CCI (int i = 0) {return(iCCI(NULL,0,CCI_Period,CCI_Price,i));}
//+------------------------------------------------------------------+
void SetCandleColor(int col, int i)
{
double high,low,bodyHigh,bodyLow;
{
bodyHigh = MathMax(Open[i],Close[i]);
bodyLow = MathMin(Open[i],Close[i]);
high = High[i];
low = Low[i];
}
Bar1[i] = low; Candle1[i] = bodyLow;
Bar2[i] = low; Candle2[i] = bodyLow;
switch(col)
{
case 1: Bar1[i] = high; Candle1[i] = bodyHigh; break;
case 2: Bar2[i] = high; Candle2[i] = bodyHigh; break;
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
for(int i = MathMax(Bars-1-IndicatorCounted(),1); i>=0; i--)
{
double cci = CCI(i);
if(cci > Overbought) SetCandleColor(1,i);
else if(cci < Oversold) SetCandleColor(2,i);
}
return(0);
}
//+------------------------------------------------------------------+
Comments