This tool is designed to enhance the visual clarity of your trading charts by dynamically highlighting price action based on momentum trends. Instead of relying solely on standard price bars, it integrates a specific technical indicator—the Commodity Channel Index (CCI)—to color-code the candles automatically.
How it Works
The logic functions by constantly monitoring the strength and direction of the market's momentum. It looks for specific "extremes" in the market to determine how the candles should appear on your screen:
- Overbought Detection: When the momentum moves significantly upward (crossing a predefined high threshold), the tool identifies these as potential overbought conditions. In response, it adjusts the visual representation of the candles to a specific color (Green) to signal this strength.
- Oversold Detection: Conversely, when the momentum drops significantly (crossing a predefined low threshold), the tool identifies these as potential oversold conditions. It then changes the visual representation of the candles to a different color (Red) to highlight this downward pressure.
Visual Presentation
The script provides a distinct visual layer on your chart using two different styles:
- Wicks: It tracks the extreme high and low points of price movement.
- Bodies: It identifies the main "body" of the candle (the distance between the opening and closing prices).
By separating these elements, the tool allows you to see at a glance whether the current market sentiment is leaning toward an overextended peak or an oversold valley. This allows for a more intuitive understanding of market extremes without needing to manually interpret complex oscillator lines.
//+------------------------------------------------------------------+
//| 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 = 14;
extern int CCI_Price = 0;
extern int Overbought = 100;
extern int Oversold = -100;
//---- 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