This script is designed to act as a monitoring tool for traders, helping them identify specific momentum shifts in the market by tracking two different versions of a technical indicator known as the Commodity Channel Index (CCI).
Core Logic Overview
The primary purpose of this tool is to detect "Zero Crosses." In trading, when a momentum indicator moves from a negative value to a positive one (or vice versa), it often signals a change in the market's strength or direction. This script automates the observation of these movements so the trader doesn't have to watch the charts constantly.
How the Analysis Works
The script operates by comparing two different timeframes of the CCI indicator simultaneously:
- The Trend Indicator: This looks at a larger perspective (the default is set to 50 periods). It is used to determine the overall "macro" direction of the market.
- The Entry Indicator: This looks at a much shorter, faster perspective (the default is set to 14 periods). It is used to identify immediate, short-term fluctuations.
Trigger Conditions
The script evaluates the data on every new price tick and looks for a specific "double confirmation." It triggers an alert only when both indicators agree on a trend change:
- Bullish Signal (Move Above Zero): The script checks if the fast Entry indicator is currently above zero, while simultaneously confirming that the slow Trend indicator has just crossed from below zero to above zero. This suggests that both short-term momentum and long-term momentum are turning positive.
- Bearish Signal (Move Below Zero): Conversely, if the fast Entry indicator is below zero and the slow Trend indicator has just crossed from above zero to below zero, it signals that both timeframes are turning negative.
User Experience & Notifications
- Real-time Alerts: When these specific conditions are met, the script generates a pop-up alert on your trading platform, notifying you of the symbol and the timeframe where the cross occurred.
- Duplicate Prevention: The logic includes a "tag" system that ensures you only receive one alert per candle. This prevents the software from spamming multiple notifications for the same price movement.
- On-Screen Display: Regardless of whether an alert is triggered, the script provides a live text display on your chart showing the current numerical values of both the Trend and Entry indicators, allowing for manual monitoring at any time.
//+------------------------------------------------------------------+
//| 2CCI_ZeroCross_Alert.mq4 |
//| Copyright © 2005, Jason Robinson (jnrtrading). |
//| http://www.jnrtrading.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)."
#property link "http://www.jnrtrading.co.uk"
#property indicator_chart_window
extern int CCI_Trend = 50;
extern int CCI_Entry = 14;
extern bool alertOn =true;
datetime alerttag;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double cciTrendNow, cciTrendPrevious, cciEntry;
cciTrendNow = iCCI(NULL, 0, CCI_Trend, PRICE_TYPICAL, 0);
cciTrendPrevious = iCCI(NULL, 0, CCI_Trend, PRICE_TYPICAL, 1);
cciEntry = iCCI(NULL, 0, CCI_Entry, PRICE_TYPICAL, 0);
//----
//Print(cciTrendNow, "...", cciTrendPrevious, "...", cciEntry);
if(cciEntry < 0) {
if((cciTrendNow < 0) && (cciTrendPrevious >= 0)&& alertOn && alerttag!=Time[0]) {
Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed below zero"); alerttag=Time[0];
}
}
else if(cciEntry > 0) {
if((cciTrendNow > 0) && (cciTrendPrevious <= 0)&& alertOn && alerttag!=Time[0]) {
Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed above zero"); alerttag=Time[0];
}
}
Comment("Trend CCI: ", cciTrendNow, " Entry CCI: ", cciEntry);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments