2CCI alerts

Author: Copyright � 2005, Jason Robinson (jnrtrading).
2CCI alerts

This script is designed as an automated monitoring tool for MetaTrader 4, specifically created to help traders identify significant momentum shifts in the market. It works by analyzing two different versions of a technical indicator known as the CCI (Commodity Channel Index) simultaneously.

Core Logic Overview

The script acts like a double-layered filter. Instead of looking at just one movement, it compares a "Trend" indicator with an "Entry" indicator. By using two different settings for these indicators, the script helps distinguish between broad market direction and immediate price action.

How It Works

The logic follows a specific sequence to determine when to notify the user:

  1. Two-Point Analysis:

    • Trend CCI: This looks at a longer timeframe or broader movement (set by default to 50 periods). It identifies the general "mood" of the market.
    • Entry CCI: This looks at shorter, faster price movements (set by default to 14 periods). It identifies immediate momentum.
  2. The Crossing Mechanism: The script is constantly watching for the exact moment these indicators cross a specific "Signal Level" (defaulted at zero). It doesn't just alert you if the numbers are high or low; it alerts you specifically when they cross from one side to the other.

  3. Validation Logic: For an alert to trigger, both indicators must agree on the direction of the move:

    • Bearish Signal: If the fast "Entry" indicator drops below the signal level, and the slower "Trend" indicator also moves below that same level from a higher position, the script triggers a notification.
    • Bullish Signal: If the fast "Entry" indicator rises above the signal level, and the slower "Trend" indicator also moves above that level from a lower position, the script triggers a notification.

User Notifications

When both indicators successfully cross the signal threshold in the same direction, the script provides three types of feedback:

  • Audio Alert: It plays a specific sound file to grab your attention immediately.
  • Pop-up Alert: A visual window appears on your trading screen showing the currency pair, the timeframe, and the direction of the cross.
  • Log Entry: It records the event in the platform's history log for later review.

In simple terms, this script filters out "noise" by ensuring that you are only notified when both short-term momentum and long-term trends align in the same direction.

Indicators Used
Commodity channel index
Miscellaneous
It plays sound alertsIt issuies visual alerts to the screen
10 Views
0 Downloads
0 Favorites
2CCI alerts
//+------------------------------------------------------------------+
//|                                         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
#include <WinUser32.mqh>

extern int CCI_Trend = 50;
extern int CCI_Entry = 14;
extern int SignalLevel = 0;
extern string Sound1 = "alert.wav";
extern string Sound2 = "alert2.wav";
//+------------------------------------------------------------------+
//| 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;
   static datetime prevtime = 0;
   
   if(prevtime == Time[0]) {
      return(0);
   }
   prevtime = Time[0];
   
   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);
   
//---- 
   
   if(cciEntry < -SignalLevel) {
      if((cciTrendNow < -SignalLevel ) && (cciTrendPrevious > -SignalLevel)) {
      PlaySound(Sound1);  
      Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed below ",-SignalLevel);
      Print(Symbol()+" M"+Period()+" Trend & Entry CCI Have both crossed below "+(-SignalLevel)+
      "\nContinue?");  
      }
   }
   else if(cciEntry > SignalLevel) {
      if((cciTrendNow > SignalLevel) && (cciTrendPrevious < SignalLevel)) {
      PlaySound(Sound2);
      Alert(Symbol()+" M"+Period()+" Trend & Entry CCI Have both crossed above ",SignalLevel);
      Print(Symbol()+" M"+Period()+" Trend & Entry CCI Have both crossed below "+SignalLevel+
      "\nContinue?");
      }
   }
   //Comment("Trend CCI: ", cciTrendNow, " Entry CCI: ", cciEntry); 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments