CCI_Trigger

Download script
CCI_Trigger

The CCITrigger is a technical analysis tool designed to help traders identify potential entry points by monitoring price momentum and trend shifts. Instead of looking at raw price action alone, this script processes data through multiple layers of mathematical smoothing to filter out market "noise" and highlight specific directional signals.

How the Logic Works

The indicator functions by calculating and comparing three primary components:

1. Base Momentum Data (CCI) The script starts by analyzing the Commodity Channel Index (CCI) for two different price points: the "Open" and the "Close" of the candles. By looking at both, the tool gains a more comprehensive view of how the price is moving relative to its recent average.

2. Moving Averages & Smoothing To prevent reacting to minor, insignificant fluctuations, the script applies different types of "Moving Averages" to the data:

  • Trigger Line: This uses a shorter period to react more quickly to recent changes in price momentum. It acts as an early warning system for immediate shifts.
  • Main Line: This uses a longer period and a specific smoothing method (Smoothed Moving Average) to represent the broader, long-term trend of the market.

Signal Generation

The core logic of the script is based on the relationship between these lines. Rather than giving a signal every time a line moves, it looks for a specific "confluence" of conditions:

  • Buy Signals: These occur when the overall trend (Main Line) is below the current price levels, and there is a specific downward momentum shift in the fast-moving trigger. Essentially, it looks for a moment where the market's underlying strength aligns with a quick price drop.
  • Sell Signals: These occur when the overall trend (Main Line) is above the current price levels, accompanied by a specific upward movement in the fast-moving trigger. This identifies moments where the long-term strength meets a quick price increase.
  • Neutral State: If these specific conditions are not met simultaneously, the script remains "Neutral," indicating that there is no clear directional bias from the data at that moment.

Summary for the User

In simple terms, this tool acts as a filter. It takes raw market data, smooths it out to see the big picture (Main Line) and the small picture (Trigger), and then looks for "cross-over" moments where both timeframes agree on a potential move. The goal is to provide a clearer distinction between actual trend changes and temporary price wobbles.

15 Views
0 Downloads
0 Favorites
CCI_Trigger
//+------------------------------------------------------------------+
//|                                                       CCITrigger |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, GideonSmolders(at)gmail.com."
#property  link      ""
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  LightBlue
#property  indicator_color2  Blue
#property  indicator_color3  LightPink
#property  indicator_color4  Pink
#property  indicator_color5  Yellow
#property  indicator_color6  Green

extern double CCIPeriod= 3;
extern double MainPeriod = 21;
extern double TriggerPeriod = 5;
//MODE_SMA  0 Simple moving average, 
//MODE_EMA  1 Exponential moving average,
//MODE_SMMA 2 Smoothed moving average, 
//MODE_LWMA 3 Linear weighted moving average. 
extern double TriggerMode = MODE_LWMA;   
extern double MainMode = MODE_SMMA;

//---- indicator buffers

string signal;
double cci_open[];
double cci_close[];
double cci_openma[];
double cci_closema[];
double TriggerCCI[];
double MainCCI[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(6);
   
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_NONE,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
   
   SetIndexBuffer(0,cci_open);
   SetIndexLabel(0,"CCIopen");
   SetIndexBuffer(1,cci_close);
   SetIndexLabel(1,"CCIclose");
   SetIndexBuffer(2,cci_openma);
   SetIndexLabel(2,"CCIopenMA");
   SetIndexBuffer(3,cci_closema);
   SetIndexLabel(3,"CCIcloseMA");
   SetIndexBuffer(4,TriggerCCI);
   SetIndexLabel(4,"Trigger CCI");
   SetIndexBuffer(5,MainCCI);
   SetIndexLabel(5,"Main Line");

   

      
//---- name for DataWindow and indicator subwindow label

   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int i;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
//---- main loop
   
//---- done
   for(i=0; i <= Bars; i++) 
   {
   cci_open[i]=iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i);
   }
   for(i=0; i <= Bars; i++) 
   { 
   cci_close[i] = iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i);
   }
   for(i=0; i <= Bars; i++) 
   {
   cci_openma[i]=(   iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i)+
                  iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i+1)
                )/2;
   }
   for(i=0; i <= Bars; i++) 
   { 
   cci_closema[i] = (   iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i)+
                  iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i+1)
                )/2;
   }
   for(i=0; i <= Bars; i++) 
   {   
   TriggerCCI[i]= iMAOnArray(cci_closema,0,TriggerPeriod,0,TriggerMode,i);
   }
   for(i=0; i <= Bars; i++) 
   {
   MainCCI[i]= iMAOnArray(cci_openma,0,MainPeriod,0,MainMode,i+1);
   }

   
   for(i=0; i<=Bars; i++)
   {
      if(MainCCI[i]>cci_openma[i] && MainCCI[i]>cci_close[i] && cci_close[i]<cci_close[i+1]
         && cci_close[i]<cci_open[i] && TriggerCCI[i]<TriggerCCI[i+1])
      signal = "SELL";
      else if (MainCCI[i]<cci_openma[i] && MainCCI[i]<cci_close[i] && cci_close[i]<cci_close[i+1]
               && cci_close[i]>cci_open[i] && TriggerCCI[i]>TriggerCCI[i+1])
      signal = "BUY";
      else
      signal = "NEUTRAL";
 
    IndicatorShortName("CCI: "+signal);
   return(0); }
  }
//+------------------------------------------------------------------+

Comments