CCI_Angle

The CCI Angle indicator is a specialized technical analysis tool designed to measure and visualize the momentum of market price movements. Instead of simply looking at the raw value of the Commodity Channel Index (CCI), this script calculates the "angle" or steepness of that movement over a specific timeframe.

Core Logic Overview

The primary purpose of this indicator is to determine whether the market is trending strongly, moving weakly, or sitting in a period of consolidation. It achieves this by comparing two different points in time:

  1. The Current Point: The value of the CCI at the present moment.
  2. The Previous Point: The value of the CCI at a set distance back in history (defined by the user as a "Shift").

By calculating the difference between these two values and adjusting them based on the distance between the points, the script determines the trajectory of the market.

Visual Interpretation

The indicator translates these mathematical calculations into a color-coded histogram, making it easy for a trader to identify market conditions at a glance:

  • Green (Upward Momentum): When the calculated angle exceeds a specific positive threshold, the histogram turns green. This indicates a strong upward trend in price momentum.
  • Red (Downward Momentum): When the calculated angle falls below a negative threshold, the histogram turns red. This indicates a strong downward trend in price momentum.
  • Yellow (Neutral/Flat Zone): When the angle is very small (near zero), it falls within a "buffer zone" defined by the user. The indicator highlights this as yellow, signaling that the market may be ranging, consolidating, or lacking a clear directional trend.

Key Parameters for Customization

Users can fine-tune how the indicator perceives "momentum" through several settings:

  • CCIPeriod: Controls the sensitivity of the underlying CCI data.
  • AngleThreshold: Sets the "sensitivity" of the colors. A higher threshold requires a steeper move to turn the bar Green or Red; a lower threshold makes the indicator more reactive to minor price changes.
  • Shift Settings (Prev/Cur): These determine the horizontal distance used to measure the angle. By widening these shifts, the user can observe longer-term trends; narrowing them allows for the detection of shorter-term fluctuations.
Indicators Used
Commodity channel index
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
CCI_Angle
//+------------------------------------------------------------------+
//|                                                    CCI_Angle.mq4 |
//|                                                           MrPip  |
//|                                                                  |
//| You can use this indicator to measure when the LSMA angle is     |
//| "near zero". AngleTreshold determines when the angle for the     |
//| LSMA is "about zero": This is when the value is between          |
//| [-AngleTreshold, AngleTreshold] (or when the histogram is red).  |
//|   LSMAPeriod: LSMA period                                        |
//|   AngleTreshold: The angle value is "about zero" when it is      |
//|     between the values [-AngleTreshold, AngleTreshold].          |      
//|   StartLSMAShift: The starting point to calculate the            |   
//|     angle. This is a shift value to the left from the            |
//|     observation point. Should be StartEMAShift > EndEMAShift.    | 
//|   EndLSMAShift: The ending point to calculate the                |
//|     angle. This is a shift value to the left from the            | 
//|     observation point. Should be StartEMAShift > EndEMAShift.    |
//|                                                                  |
//|   Modified by MrPip from EMAAngle by jpkfox                      |                                              |
//|       Red for down                                               |
//|       Yellow for near zero                                       |
//|       Green for up                                               |   
//|                                                                  |
//| Modified to do CCI Angle                                         |
//+------------------------------------------------------------------+

#property  copyright "Robert L. Hill aka MrPip"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  LimeGreen
#property  indicator_color2  Yellow
#property  indicator_color3 FireBrick
//---- indicator parameters
extern int CCIPeriod=14;
extern double AngleTreshold=15.0;
extern int PrevShift=4;
extern int CurShift=0;

//---- indicator buffers
double UpBuffer[];
double DownBuffer[];
double ZeroBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);

//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,UpBuffer) &&
      !SetIndexBuffer(1,DownBuffer) &&
      !SetIndexBuffer(2,ZeroBuffer))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("CCI_Angle("+CCIPeriod+","+AngleTreshold+","+PrevShift+","+CurShift+")");
//---- initialization done
   return(0);
}



//+------------------------------------------------------------------+
//| The angle for LSMA                                               |
//+------------------------------------------------------------------+
int start()
{
   double fCur, fPrev;
   double fAngle, mFactor;
   int nLimit, i;
   int nCountedBars;
   double angle;
   int ShiftDif;
 
   if(CurShift >= PrevShift)
   {
      Print("Error: CurShift >= PrevShift");
      PrevShift = 6;
      CurShift = 0;      
   }  
         
   nCountedBars = IndicatorCounted();
//---- check for possible errors
   if(nCountedBars<0) 
      return(-1);
//---- last counted bar will be recounted
   if(nCountedBars>0) 
      nCountedBars--;
   nLimit = Bars-nCountedBars;

   mFactor = 1.0;
   ShiftDif = PrevShift-CurShift;
   mFactor /= ShiftDif; 
 
//---- main loop
   for(i=0; i<nLimit; i++)
   {
      fCur=iCCI(NULL, 0, CCIPeriod, PRICE_CLOSE, i+CurShift);
      fPrev=iCCI(NULL, 0, CCIPeriod, PRICE_CLOSE, i+PrevShift);
      // 10000.0 : Multiply by 10000 so that the fAngle is not too small
      // for the indicator Window.
      fAngle = mFactor * (fCur - fPrev)/2;

      DownBuffer[i] = 0.0;
      UpBuffer[i] = 0.0;
      ZeroBuffer[i] = 0.0;
      
      if(fAngle > AngleTreshold)
         UpBuffer[i] = fAngle;
      else if (fAngle < -AngleTreshold)
         DownBuffer[i] = fAngle;
      else ZeroBuffer[i] = fAngle;
   }

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

Comments