CCM3_v1

This script is a sophisticated technical analysis indicator designed to interpret market price action by analyzing the relationship between "candle bodies" and "candle wicks" (the tails) over a specific period. Instead of simply looking at price movement, it attempts to quantify the intensity of buying and selling pressure through a multi-layered mathematical approach.

Core Logic Breakdown

1. Data Categorization (Body vs. Wick) The logic begins by breaking down each price bar into three distinct components:

  • The Body: The difference between the opening and closing prices.
  • The Upper Wick: The distance between the high price and the top of the candle body.
  • The Lower Wick: The distance between the low price and the bottom of the candle body.

The script calculates moving averages for these three components to establish a baseline of "normal" behavior for the current market trend.

2. Volatility Bands (Standard Deviation) To understand if a specific candle is an outlier, the logic employs a method similar to Bollinger Bands. It calculates the standard deviation for the bodies and both wicks. This allows the script to create dynamic "zones." If a candle's wick or body extends significantly beyond these calculated zones, the script identifies it as having high volatility or extreme momentum.

3. Sentiment Scoring (The Coding System) This is the heart of the script. It iterates through recent bars and assigns a numerical score to each based on how they relate to the current bar:

  • It checks if a previous candle was bullish or bearish.
  • It compares the size of those bodies against the "volatility bands" mentioned above.
  • It rewards/penalizes the score based on whether the wicks are pushing into specific zones. Essentially, it is "scoring" the market's aggression—determining if buyers or sellers are successfully pushing the price or if they are being exhausted (resulting in long wicks).

4. Weighting and Smoothing Once the raw scores are gathered for a sequence of candles, the logic applies a complex weighting system:

  • Weighting Function: It uses a mathematical formula to give more importance to certain bars in the sequence than others.
  • The "FATL" Calculation: Finally, it performs a highly specific linear combination (a weighted sum) of 39 different data points. This serves as a final smoothing process to filter out market "noise," resulting in a cleaner signal line.

Visual Representation

On your chart, the logic produces three distinct visual elements:

  • A Signal Line: A main moving line that represents the filtered sentiment score.
  • Upward/Downward Histograms: These provide a visual representation of whether the momentum is trending toward the "Up" or "Down" scores, helping to identify the strength of the current move quickly.

Summary for the User

In simple terms, this tool doesn't just tell you that the price went up or down; it analyzes how it moved. It looks at the "effort" vs. "result" of the market—detecting when a move is strong and supported by volume/momentum versus when it is weak and struggling, providing a more nuanced view of market sentiment than standard moving averages.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
CCM3_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| CCM3.mq4 
//| Ramdass - Conversion only
//+------------------------------------------------------------------+
#property  copyright "Author := Keny"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Green
#property indicator_color3 Red

//---- input parameters
extern int n=6;
extern int len=9;
extern double StdUp=0.5;
extern double StdDown=-0.5;
extern double a0=0.0;
extern double b0=0.0;
extern double c0=-1.0;
extern int CountBars=200;

//---- buffers
double SigL[];
double Up[];
double Dw[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(3);
   SetIndexBuffer(0,SigL);
   SetIndexBuffer(1,Up);
   SetIndexBuffer(2,Dw);   
   SetIndexStyle(0,DRAW_LINE,0,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,2); 
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2);


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| CCM + Digi                                                       |
//+------------------------------------------------------------------+
int start()
  {
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+39);  
   SetIndexDrawBegin(1,Bars-CountBars+39); 
   SetIndexDrawBegin(2,Bars-CountBars+39); 
   int shift,i,i2,cnt,len1,k;
   int counted_bars=IndicatorCounted();
   double value1,value3,M1,M2,M3,Hi1,Lo1,price,code;
   double b1,b2,u1,u2,l1,l2,V0,V1,V2,V3;
   double xOC,xHMOC,xMOCL,EMA0,EMAcode,cci;
   double code1[61],OC[61],HMOC[61],MOCL[61],MAxOC[61],MAxHMOC[61],MAxMOCL[61],WF[60];
//----
   if(Bars<=60) return(0);
   len1=len;
   if (len1>60) len1=60;


//---- initial zero
   if(counted_bars<60)
   {
      for(i=1;i<=0;i++) SigL[CountBars-i]=0.0;
      for(i=1;i<=0;i++) Up[CountBars-i]=0.0;
      for(i=1;i<=0;i++) Dw[CountBars-i]=0.0;
   }
//----
   for (i=0; i<=n-1; i++)
   {
   	WF[i]=MathPow(i-b0,a0)*MathExp(c0*(i-b0));
   }

   shift=CountBars-1;

   while(shift>=0)
     {
         for (i=len1-1; i>=1; i--)
                { //ïåðåïèñûâàåì ìàññèâû - äëÿ áîëëèíäæåðà
                        OC[i]=OC[i-1];
                        HMOC[i]=HMOC[i-1];
                        MOCL[i]=MOCL[i-1];
                        MAxOC[i]=MAxOC[i-1];
                        MAxHMOC[i]=MAxHMOC[i-1];
                        MAxMOCL[i]=MAxMOCL[i-1];
                }
        for (i=38; i>=1; i--)
                {
                        code1[i]=code1[i-1];
                }
        EMA0=EMAcode;


OC[0]=MathAbs(Open[shift]-Close[shift]);  
HMOC[0]=High[0]-MathMax(Open[shift],Close[shift]);
MOCL[0]=MathMin(Open[shift],Close[shift])-Low[shift];
MAxOC[0]=(MAxOC[1]-OC[len1-1])+OC[0];
MAxHMOC[0]=MAxHMOC[1]-HMOC[len-1]+HMOC[0];
MAxMOCL[0]=MAxMOCL[1]-MOCL[len1-1]+MOCL[0];

xOC=MAxOC[0]/len1;
xHMOC=MAxHMOC[0]/len1;
xMOCL=MAxMOCL[0]/len1;
V1=0;
V2=0;
V3=0;

        for (i=0; i<=len1-1; i++)
        {
                V0=OC[i]-xOC;
                V0=V0*V0;
                V1=V1+V0;
                V0=HMOC[i]-xHMOC;
                V0=V0*V0;
                V2=V2+V0;
                V0=MOCL[i]-xMOCL;
                V0=V0*V0;
                V3=V3+V0;
        }

V1=V1/len1;
V1=MathSqrt(V1);
V2=V2/len1;
V2=MathSqrt(V2);
V3=V3/len1;
V3=MathSqrt(V3);
b1=xOC+StdDown*V1; //b1,b2-BB äëÿ òåë
b2=xOC+StdUp*V1;
u1=xHMOC+StdDown*V2;//u1,u2-BB äëÿ âåðõíåé òåíè
u2=xHMOC+StdUp*V2;
l1=xMOCL+StdDown*V3;//l1,l2-BB äëÿ íèæíåé òåíè
l2=xMOCL+StdUp*V3;
code1[0]=0.0;

for (i=0; i<=n-1; i++) //êîäèðóåì ñâå÷ó
{

Hi1=High[shift]; Lo1=Low[shift]; 
      for (k=shift; k<=shift+n-1; k++)
        {
         price=High[k];
         if(Hi1<=price) Hi1=price;
         price=Low[k];
         if(Lo1>price)  Lo1=price;
        }


code=0;
if (Open[shift+i]<Close[shift]) code=64;
if (Close[shift]==Open[shift+i])

 {
  if ( Hi1-MathMax(Close[shift],Open[shift+i])>=MathMin(Close[shift],Open[shift+i])-Lo1 ) code=64;
 }
if (code>=64)
{
//if (Open[shift+i]==Close[shift]) code=code;
if ( (MathAbs(Open[shift+i]-Close[shift+i])<b1) && (MathAbs(Open[shift+i]-Close[shift])>0) ) code=code+16;
if ( (MathAbs(Open[shift+i]-Close[shift])>=b1) && ((MathAbs(Open[shift+i]-Close[shift])<b2)) ) code=code+32;
if (MathAbs(Open[shift+i]-Close[shift])>=b2) code=code+48;
}

if (code<64)
{
if (Open[shift+i]==Close[shift]) code=code+48;
if ( (MathAbs(Open[shift+i]-Close[shift])<b1) && (MathAbs(Open[shift+i]-Close[shift])>0) ) code=code+32;
if ( (MathAbs(Open[shift+i]-Close[shift])>=b1) && ((MathAbs(Open[shift+i]-Close[shift+i])<b2)) ) code=code+16;
//if (MathAbs(Open[shift+i]-Close[shift])>=b2) code=code;
}

if (Hi1-MathMax(Open[shift+i],Close[shift])<u1 && Hi1-MathMax(Open[shift+i],Close[shift])>0) code=code+4;
if (Hi1-MathMax(Open[shift+i],Close[shift])>=u1 && Hi1-MathMax(Open[shift+i],Close[shift])<u2) code=code+8;
if (Hi1-MathMax(Open[shift+i],Close[shift])>=u2) code=code+12;

if (MathMin(Open[shift+i],Close[shift])-Lo1==0) code=code+3;
if (MathMin(Open[shift+i],Close[shift])-Lo1<l1 && MathMin(Open[shift+i],Close[shift])-Lo1>0) code=code+2;
if (MathMin(Open[shift+i],Close[shift])-Lo1>=l1 && MathMin(Open[shift+i],Close[shift])-Lo1<l2) code=code+1;

code1[0]=code1[0]+(code-63)*WF[i];

}

cnt=cnt+1;
if (cnt>39) //ñãëàæèâàåì ñ ïîìîùüþ FATL îò Finvare
{
SigL[shift] = 
0.4360409450*code1[0]
+0.3658689069*code1[1]
+0.2460452079*code1[2]
+0.1104506886*code1[3]
-0.0054034585*code1[4]
-0.0760367731*code1[5]
-0.0933058722*code1[6]
-0.0670110374*code1[7]
-0.0190795053*code1[8]
+0.0259609206*code1[9]
+0.0502044896*code1[10]
+0.0477818607*code1[11]
+0.0249252327*code1[12]
-0.0047706151*code1[13]
-0.0272432537*code1[14]
-0.0338917071*code1[15]
-0.0244141482*code1[16]
-0.0055774838*code1[17]
+0.0128149838*code1[18]
+0.0226522218*code1[19]
+0.0208778257*code1[20]
+0.0100299086*code1[21]
-0.0036771622*code1[22]
-0.0136744850*code1[23]
-0.0160483392*code1[24]
-0.0108597376*code1[25]
-0.0016060704*code1[26]
+0.0069480557*code1[27]
+0.0110573605*code1[28]
+0.0095711419*code1[29]
+0.0040444064*code1[30]
-0.0023824623*code1[31]
-0.0067093714*code1[32]
-0.0072003400*code1[33]
-0.0047717710*code1[34]
+0.0005541115*code1[35]
+0.0007860160*code1[36]
+0.0130129076*code1[37]
+0.0040364019*code1[38];

}
Up[shift]=0.0; Dw[shift]=0.0;
if (code1[0]>=code1[1]) {Up[shift]=code1[0];} else {Dw[shift]=code1[0];}
      shift--;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments