CCI_TriggerBars

CCI_TriggerBars

This tool is designed to analyze market momentum and provide visual trend signals for traders using the MetaTrader platform. It operates by calculating specific mathematical movements based on price data and comparing them to identify potential buying or selling opportunities.

How the Logic Works

1. Data Gathering The script begins by gathering two primary pieces of information from the market: the opening prices and the closing prices of each candle over a specific timeframe. It uses a standard momentum indicator (CCI) as the foundation for these calculations to gauge how far the price is moving away from its average.

2. Trend Analysis & Smoothing Instead of looking at raw, jagged price movements which can be noisy and misleading, the script processes that data into two distinct smoothed lines:

  • The Trigger Line: This is a smoothed version of the opening prices. It acts as a sensitivity marker to help identify shifts in momentum.
  • The Main Line: This is a different type of smoothed average calculated from the same data. It serves as the primary reference point for the overall trend direction.

3. Signal Generation The core logic of the script relies on the relationship between these two lines. By comparing where the "Main Line" sits in relation to the "Trigger Line," the tool categorizes the market into three specific states:

  • BUY Signal: Occurs when the Main Line drops below the Trigger Line, suggesting downward momentum or a shift that may favor a buying opportunity depending on your strategy.
  • SELL Signal: Occurs when the Main Line rises above the Trigger Line, indicating upward momentum or a trend shift favoring a sell position.
  • NEUTRAL State: If neither of the above conditions is met—meaning the lines are in a state of equilibrium—the tool identifies the market as neutral, suggesting a lack of a clear directional bias.

Visual Output

The script provides a visual dashboard in a separate window on your chart. It uses a histogram format to display these trends clearly, allowing you to see at a glance whether the current market environment is trending toward a Buy, a Sell, or remaining in a Neutral state.

Indicators Used
Commodity channel indexMoving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
CCI_TriggerBars
//+------------------------------------------------------------------+
//|                                                       CCITrigger |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, GideonSmolders."
#property  link      ""
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Olive
#property  indicator_color2  FireBrick
#property  indicator_color3  DarkKhaki
#property indicator_maximum 1
#property indicator_minimum 0

//---- indicator buffers

string signal;
double BUYtrend[];
double SELLtrend[];
double NEUTRAL[];

double cci_open[];
double cci_close[];
double TriggerCCI[];
double MainCCI[];




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(7);
   
//---- drawing settings

   
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);

   
   SetIndexBuffer(3,cci_open);
   SetIndexLabel(3,"CCIopen");
   SetIndexBuffer(4,cci_close);
   SetIndexLabel(4,"CCIclose");
   SetIndexBuffer(5,TriggerCCI);
   SetIndexLabel(5,"Trigger CCI");
   SetIndexBuffer(6,MainCCI);
   SetIndexLabel(6,"Main Line");

   SetIndexBuffer(0,BUYtrend);
   SetIndexLabel(0,"BUY");
   SetIndexBuffer(1,SELLtrend);
   SetIndexLabel(1,"SELL");
   SetIndexBuffer(2,NEUTRAL);
   SetIndexLabel(2,"NEUTRAL");




      
//---- 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(),60,7,PRICE_OPEN,i);
   }
   for(i=0; i <= Bars; i++) 
   { 
   cci_close[i] =  iCCI(Symbol(),60,7,PRICE_CLOSE,i);
   }
   for(i=0; i <= Bars; i++) 
   {   
   TriggerCCI[i]= iMAOnArray(cci_open,0,5,0,MODE_SMMA,i);
   }
   for(i=0; i <= Bars; i++) 
   {
   MainCCI[i]= iMAOnArray(cci_open,0,5,1,MODE_LWMA,i);
   }

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

Comments