CCI_Cross0_x3WarnSigAlertEli_MTF

Download script
Author: Copyright � 2006, Eli Hayun
CCI_Cross0_x3WarnSigAlertEli_MTF

This script is a multi-layered technical analysis tool designed to identify momentum shifts in financial markets by tracking three different speeds of the Commodity Channel Index (CCI). Instead of providing a single line on your chart, it acts as an automated signaling system that places visual markers (arrows) on your screen whenever specific price movements occur.

Core Logic and Functionality

The script operates based on three distinct "speeds" of market analysis simultaneously:

  • Fast Analysis: Tracks immediate, short-term momentum.
  • Slow Analysis: Monitors medium-term trends to filter out minor market noise.
  • Very Slow Analysis: Observes long-term structural movements to identify broader market shifts.

How the Signals are Generated

The logic focuses on "Zero-Cross" events. The script constantly monitors the CCI value for all three speeds. When a specific speed moves from a negative value to a positive value (or vice versa), it triggers a visual signal:

  1. Trend Direction:

    • Upward Signals: Triggered when the indicator crosses from below zero to above zero, suggesting bullish momentum.
    • Downward Signals: Triggered when the indicator crosses from above zero to below zero, suggesting bearish momentum.
  2. Visual Positioning: The script does not just place arrows randomly; it calculates a "Signal Gap" based on recent market volatility (using the Average True Range). This ensures that the arrows appear at a consistent distance away from the price candles, making them easy to see without cluttering the actual price action.

  3. Multi-Timeframe Awareness: A key feature of this logic is its ability to look at higher timeframes while you are viewing a lower one. It can calculate signals based on larger market structures (like Hourly or Daily data) and project those signals onto your current chart, providing a more comprehensive view of the "big picture."

Alerts and Notifications

To ensure traders do not miss these movements, the script includes an automated notification system:

  • Sound & Text: When a signal occurs on a new price candle, the script can trigger an audible alert sound.
  • On-Screen Comments: It dynamically displays a text comment at the top of your chart area, identifying exactly which timeframe and which speed (Fast, Slow, or Very Slow) just triggered a signal.
  • Smart Filtering: The logic is designed to only announce a signal once per candle, preventing the screen from being flooded with repetitive alerts during volatile price swings.

Summary for the User

This tool simplifies complex momentum tracking by distilling three different types of market data into clear visual cues. It tells you when the "mood" of the market is shifting at different speeds, allowing you to see where short-term hype meets long-term trends at a single glance.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains open time of each bar
Indicators Used
Indicator of the average true rangeCommodity channel index
Miscellaneous
Implements a curve of type %1It plays sound alerts
15 Views
0 Downloads
0 Favorites
CCI_Cross0_x3WarnSigAlertEli_MTF
//+------------------------------------------------------------------+
//|                                                    CCI_Cross.mq4 |
//|                                      Copyright © 2006, Eli Hayun |
//|                                          http://www.elihayun.com |
//|                                       Built for ValeoFX          |
//+------------------------------------------------------------------+
//mod2008fxtsd    ki
#property copyright "Copyright © 2006, Eli Hayun"
#property link      "http://www.elihayun.com"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 BlueViolet//28-CCi
#property indicator_color2 BlueViolet
#property indicator_color3 Red//15-CCi
#property indicator_color4 Red
#property indicator_color5 Blue//5-CCi
#property indicator_color6 Blue
#property indicator_color7 Yellow
#property indicator_color8 Goldenrod



#property indicator_width1 4
#property indicator_width2 4
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 0
#property indicator_width8 1

//---- input parameters

extern int       FastCCIperiod=5;
extern int       FastCCIprice=5;
extern bool FastCCI_on  =true;
extern int       SlowCCIperiod=15;
extern int       SlowCCIprice=5;
extern bool SlowCCI_on  =true;
extern int       VerySlowCCIperiod=28;
extern int       VerySlowCCIprice=5;
extern bool VerySlowCCI_on =true;

extern bool    AlertsOn  =true;
extern string  AlertSoundFile="wait.wav";

extern double  SignalGap =0.8;
extern int     TimeFrame =0;


extern string   note_Price = "0C 1O 2H 3L 4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN;0 currentTF";

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   TimeFrame= MathMax(TimeFrame,Period());

   if (FastCCI_on)
   {
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,225);//217 233
   SetIndexBuffer(5,ExtMapBuffer1);
   SetIndexEmptyValue(5,0.0);

   SetIndexStyle(4,DRAW_ARROW);  
   SetIndexArrow(4,226);//218 234
   SetIndexBuffer(4,ExtMapBuffer2);
   SetIndexEmptyValue(4,0.0);

   SetIndexLabel(5,"CCI ("+FastCCIperiod+") M"+TimeFrame+" cross0 UP");
   SetIndexLabel(4,"CCI ("+FastCCIperiod+") M"+TimeFrame+" cross0 DN");
   }
   

   if (SlowCCI_on)
   {   
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,233);
   SetIndexBuffer(3,ExtMapBuffer3);
   SetIndexEmptyValue(3,0.0);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,234);
   SetIndexBuffer(2,ExtMapBuffer4);
   SetIndexEmptyValue(2,0.0);

   SetIndexLabel(3,"CCI ("+SlowCCIperiod+") M"+TimeFrame+" cross0 UP");
   SetIndexLabel(2,"CCI ("+SlowCCIperiod+") M"+TimeFrame+" cross0 DN");
   }
   

   if (VerySlowCCI_on)
   {      
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,241);
   SetIndexShift(1,-TimeFrame/Period());
   SetIndexBuffer(1,ExtMapBuffer5);
   SetIndexEmptyValue(1,0.0);

   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,242);
   SetIndexShift(0,-TimeFrame/Period());
   SetIndexBuffer(0,ExtMapBuffer6);
   SetIndexEmptyValue(0,0.0);

   SetIndexLabel(1,"CCI ("+VerySlowCCIperiod+") M"+TimeFrame+" cross0 UP");
   SetIndexLabel(0,"CCI ("+VerySlowCCIperiod+") M"+TimeFrame+" cross0 DN");
   }


   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,226);//167158159178115
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexEmptyValue(6,0.0);
   SetIndexLabel(6,"CCI("+FastCCIperiod+")0cross WarningSignal");
//
   SetIndexStyle(7,DRAW_ARROW);
   SetIndexArrow(7,234);//167159178170167
   SetIndexBuffer(7,ExtMapBuffer8);
   SetIndexEmptyValue(7,0.0);
   SetIndexLabel(7,"CCI("+SlowCCIperiod+")0cross WarningSignal");



   IndicatorShortName("CCI x3 Cross0 ["+TimeFrame+"]");  


   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int    shift,y=0,limit,counted_bars=IndicatorCounted();
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;

   datetime TimeArray[];
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 

   limit = Bars-counted_bars;
   limit = MathMax (limit,TimeFrame/Period());
   
   for(shift=0,y=0;shift<limit;shift++)
   {
   if (Time[shift]<TimeArray[y]) y++; 

 double high  = iHigh(NULL, TimeFrame, y);
 double high1 = iHigh(NULL, TimeFrame, y+1);

 double low   = iLow (NULL, TimeFrame, y);
 double low1  = iLow (NULL, TimeFrame, y+1);

 double signalgap = MathCeil(iATR(NULL,TimeFrame,10,y)/Point)*SignalGap;   
 
 
 
   if (FastCCI_on)
      {
      
      ExtMapBuffer1[shift] = 0.0; ExtMapBuffer2[shift] = 0.0; ExtMapBuffer7[shift] = 0.0;

      double fCCI_0 = iCCI(NULL, TimeFrame, FastCCIperiod, FastCCIprice, y);
      double fCCI_1 = iCCI(NULL, TimeFrame, FastCCIperiod, FastCCIprice, y+1);
 //   double fCCI_2 = iCCI(NULL, 0, FastCCI, PRICE_TYPICAL, shift+2);
     
      if (fCCI_0 > 0 && fCCI_1<0 ){
         ExtMapBuffer1[shift] = low  - signalgap * Point; 
         ExtMapBuffer7[0]=ExtMapBuffer1[0];    SetIndexArrow(6,225);ExtMapBuffer7[1]=0.0;}

      if (fCCI_0 < 0 && fCCI_1>0 ){
         ExtMapBuffer2[shift] = high + signalgap *  Point;
         ExtMapBuffer7[0]=ExtMapBuffer2[0];   SetIndexArrow(6,226); }

      }

   if (SlowCCI_on)
      {
      ExtMapBuffer3[shift] = 0.0; ExtMapBuffer4[shift] = 0.0;  ExtMapBuffer8[shift] = 0.0;
         
      double sCCI_0 = iCCI(NULL, TimeFrame, SlowCCIperiod, SlowCCIprice, y);
      double sCCI_1 = iCCI(NULL, TimeFrame, SlowCCIperiod, SlowCCIprice, y+1);
//    double sCCI_2 = iCCI(NULL, TimeFrame, SlowCCIperiod, SlowCCIprice, y+2);
      
      if (sCCI_0>0 && sCCI_1 < 0 ){
         ExtMapBuffer3[shift] = low  - 1.2 *signalgap * Point;  
         ExtMapBuffer8[0]= ExtMapBuffer3[0];SetIndexArrow(7,233);}
      
      if (sCCI_0<0 && sCCI_1 > 0 ){
         ExtMapBuffer4[shift]= high + 1.2 *signalgap * Point; 
         ExtMapBuffer8[0]=  ExtMapBuffer4[0];   SetIndexArrow(7,234);}
     
      }
      
   if (VerySlowCCI_on)
      {         
      ExtMapBuffer5[shift] = 0.0; ExtMapBuffer6[shift] = 0.0;

//    double vsCCI_0 = iCCI(NULL,TimeFrame, VerySlowCCIperiod, PRICE_OPEN, y);
      double vsCCI_1 = iCCI(NULL,TimeFrame, VerySlowCCIperiod, VerySlowCCIprice, y+1);
      double vsCCI_2 = iCCI(NULL,TimeFrame, VerySlowCCIperiod, VerySlowCCIprice, y+2);
      
      if (vsCCI_1>0 && vsCCI_2<0)
      ExtMapBuffer5[shift] = low1 - 1.5*signalgap * Point; 

      if (vsCCI_1<0&& vsCCI_2>0)
      ExtMapBuffer6[shift] = high1 + 1.5*signalgap * Point; 
      }
  
  
   }

   string sComment = "";
   
 if(AlertsOn) 
   {
   if (FastCCI_on)
      {
   if (ExtMapBuffer1[0] != 0)
      sComment = sComment + " CCI ("+FastCCIperiod+") M"+TimeFrame+" UP ";
      
   if (ExtMapBuffer2[0] != 0)
      sComment = sComment + " CCI ("+FastCCIperiod+") M"+TimeFrame+" Down ";
      }

   if (SlowCCI_on)
      {
   if (ExtMapBuffer3[0] != 0)
      sComment = sComment + " CCI ("+SlowCCIperiod+") M"+TimeFrame+" UP ";
      
   if (ExtMapBuffer4[0] != 0)
      sComment = sComment + " CCI ("+SlowCCIperiod+") M"+TimeFrame+" Down ";
      }
      
   if (VerySlowCCI_on) 
      {     
   if (ExtMapBuffer5[0] != 0)
      sComment = sComment + " CCI3 ("+VerySlowCCIperiod+") M"+TimeFrame+" UP ";
      
   if (ExtMapBuffer6[0] != 0)
      sComment = sComment + " CCI3 ("+VerySlowCCIperiod+") M"+TimeFrame+"] Down ";
      }
   }
 

   if ((sComment != "") && (!IsTesting()))
   {
      if (NewBar())
      {
         PlaySound(AlertSoundFile);//"expert.wav"wait.wav;
         Print(Symbol(), " ", sComment);
      }
      Comment(TimeToStr(CurTime()), " ", sComment);
   }
   if ((sComment == "") && (!IsTesting()))
   {
      Comment("");
   }

   return(0);
}
//+------------------------------------------------------------------+

bool NewBar()
{
   static datetime dt = 0;
   if (dt != Time[0])
   {
      dt = Time[0];
      return(true);
   }
   return(false);
}

Comments