This script is a technical trading tool designed for the MetaTrader 4 platform. Its primary purpose is to monitor price momentum and provide visual signals on a chart when specific mathematical "crossings" occur between three different speeds of the Commodity Channel Index (CCI).
Core Logic Overview
The indicator operates by tracking three distinct versions of the CCI, which is a momentum-based oscillator used to measure how far the current price is moving away from its average. By using three different settings—Fast, Slow, and Very Slow—the script attempts to filter out market "noise" and identify significant shifts in trend direction.
How the Signals are Generated
The script constantly scans the most recent price data and compares the current state of the CCI against its values from two periods ago. It looks for a specific "crossover" event:
- Bullish Signals (Upward Momentum): The logic checks if the indicator has moved from a negative value (below the zero line) to a positive value. When this happens, it identifies a potential upward move and places an arrow below the price candle on the chart.
- Bearish Signals (Downward Momentum): Conversely, the logic checks if the indicator has moved from a positive value to a negative value. When this occurs, it identifies a potential downward move and places an arrow above the price candle.
Multi-Layered Analysis
To provide a more comprehensive view of the market, the script processes these three speeds simultaneously:
- Fast CCI: Provides immediate reactions to price changes (labeled as "1st" signals).
- Slow CCI: Provides a moderate confirmation of the trend (labeled as "2nd" signals).
- Very Slow CCI: Tracks the broader, long-term momentum (labeled as "3rd" signals).
User Interface and Alerts
The script is designed to be highly interactive for the trader:
- Visual Cues: It automatically places different types of arrows on the chart to represent the various signal strengths.
- On-Screen Text: It displays a real-time text comment in the corner of the chart, identifying exactly which type of signal (e.g., "1st UP" or "3rd Down") has been triggered.
- Audio Alerts: To ensure the trader doesn't miss an entry point, the script is programmed to play a sound notification and print a log entry in the system console whenever a new signal is detected on a fresh price candle.
//+------------------------------------------------------------------+
//| CCI_Cross.mq4 |
//| Copyright © 2006, Eli Hayun |
//| http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli Hayun"
#property link "http://www.elihayun.com"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red// Kleurloos
#property indicator_color2 DodgerBlue//Kleurloos
#property indicator_color3 Red//DodgerBlue
#property indicator_color4 Red
#property indicator_color5 DodgerBlue//Kleurloos
#property indicator_color6 Red//Kleurloos
//---- input parameters
extern int FastCCI=25;
extern int SlowCCI=50;
extern int VerySlowCCI=50;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID, 2);
SetIndexArrow(0,217);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID, 2);
SetIndexArrow(1,218);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID, 2);
SetIndexArrow(2,233);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_NONE);
SetIndexArrow(3,234);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,241);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,242);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexEmptyValue(5,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int shift;
for(shift=Bars-1;shift>=0;shift--)
{
ExtMapBuffer1[shift] = 0; ExtMapBuffer2[shift] = 0; ExtMapBuffer3[shift] = 0;
ExtMapBuffer4[shift] = 0; ExtMapBuffer5[shift] = 0; ExtMapBuffer6[shift] = 0;
double fCCI_0 = iCCI(NULL, 0, FastCCI, PRICE_TYPICAL, shift);
double fCCI_1 = iCCI(NULL, 0, FastCCI, PRICE_TYPICAL, shift+1);
double fCCI_2 = iCCI(NULL, 0, FastCCI, PRICE_TYPICAL, shift+2);
if (fCCI_0 > 0 && fCCI_1<0 && fCCI_2 < 0)
ExtMapBuffer1[shift] = Low[shift] - 3 * Point;
if (fCCI_0 < 0 && fCCI_1>0 && fCCI_2 > 0)
ExtMapBuffer2[shift] = High[shift] + 3 * Point;
double sCCI_0 = iCCI(NULL, 0, SlowCCI, PRICE_TYPICAL, shift);
double sCCI_1 = iCCI(NULL, 0, SlowCCI, PRICE_TYPICAL, shift+1);
double sCCI_2 = iCCI(NULL, 0, SlowCCI, PRICE_TYPICAL, shift+2);
if (sCCI_0 > 0 && sCCI_1<0 && sCCI_2 < 0)
ExtMapBuffer3[shift] = Low[shift] - 4 * Point;
if (sCCI_0 < 0 && sCCI_1>0 && sCCI_2 > 0)
ExtMapBuffer4[shift] = High[shift] + 4 * Point;
double vsCCI_0 = iCCI(NULL, 0, VerySlowCCI, PRICE_TYPICAL, shift);
double vsCCI_1 = iCCI(NULL, 0, VerySlowCCI, PRICE_TYPICAL, shift+1);
double vsCCI_2 = iCCI(NULL, 0, VerySlowCCI, PRICE_TYPICAL, shift+2);
if (vsCCI_0 > 0 && vsCCI_1<0 && vsCCI_2 < 0)
ExtMapBuffer5[shift] = Low[shift] - 5 * Point;
if (vsCCI_0 < 0 && vsCCI_1>0 && vsCCI_2 > 0)
ExtMapBuffer6[shift] = High[shift] + 5 * Point;
}
string sComment = "";
if (ExtMapBuffer1[0] != 0)
sComment = sComment + " 1st UP";
if (ExtMapBuffer2[0] != 0)
sComment = sComment + " 1st Down";
if (ExtMapBuffer3[0] != 0)
sComment = sComment + " 2nd UP";
if (ExtMapBuffer4[0] != 0)
sComment = sComment + " 2nd Down";
if (ExtMapBuffer5[0] != 0)
sComment = sComment + " 3rd UP";
if (ExtMapBuffer6[0] != 0)
sComment = sComment + " 3rd Down";
if ((sComment != "") && (!IsTesting()))
{
if (NewBar())
{
PlaySound("expert.wav");
Print(Symbol(), " ", sComment);
}
Comment(TimeToStr(CurTime()), " ", sComment);
}
if ((sComment == "") && (!IsTesting()))
{
Comment("");
}
return(0);
}
//+------------------------------------------------------------------+
bool NewBar()
{
static datetime dt = 0;
//if (dt == 0) dt = Time[0];
if (dt != Time[0])
{
dt = Time[0];
return(true);
}
return(false);
}
Comments