to_ind_CandlCode_ICS

Download script
Author: Integer
to_ind_CandlCode_ICS

The CandlCode ICS indicator is designed to quantify the "anatomy" of a price candle into a numerical value. Instead of simply looking at whether a price went up or down, this script analyzes the specific proportions of each candle—measuring the body size, the upper shadow, and the lower shadow—and compares those dimensions against historical volatility to produce a unique score.

How the Logic Works

1. Dimensional Analysis The script begins by breaking down every individual price candle into three primary components:

  • The Body: The distance between the opening and closing prices.
  • The Lower Shadow: The distance from the low point to the bottom of the body.
  • The Upper Shadow: The distance from the high point to the top of the body.

2. Dynamic Volatility Thresholds To determine if a candle is "large," "small," or "average," the script doesn't use a fixed number. Instead, it uses a moving average calculation (Bollinger Band logic) on those dimensions over a set period. This creates dynamic boundaries (Upper and Lower Thresholds). This allows the indicator to adapt automatically; what constitutes a "large candle" in a quiet market will be different from a "large candle" during a high-volatility news event.

3. Scoring System The script then assigns specific numerical values based on how the current candle's dimensions relate to those dynamic thresholds:

  • Body Scoring: It checks if the body is significantly smaller than the lower threshold, within the normal range, or larger than the upper threshold. It also factors in whether the price closed higher or lower than it opened.
  • Shadow Scoring: It evaluates the length of the upper and lower shadows against the calculated thresholds to see how much "rejection" or "exhaustion" occurred at the highs and lows of that specific period.

4. Data Aggregation and Smoothing The script adds these three scores (Body + Lower Shadow + Upper Shadow) together to create a final Candle Code.

Because raw market data can be "noisy," the indicator performs a triple-smoothing process on this final score. It applies a moving average three times in succession. This filters out minor fluctuations, resulting in a much smoother line that highlights the underlying trend of candle behavior over time.

Visual Representation

The output is displayed in a separate window as two primary lines:

  • CandlCode ICS (Red): The raw calculated score reflecting immediate price action.
  • CandlCode ICS Smoothed (Yellow): A refined, stabilized version of the score used to identify broader trends in candle behavior more clearly.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
to_ind_CandlCode_ICS
//+------------------------------------------------------------------+
//|                                         to_ind_CandlCode_ICS.mq4 |
//|                                                                * |
//|                                                                * |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link      "for-good-letters@yandex.ru"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Yellow
#property indicator_minimum 0
#property indicator_maximum 128
#property indicator_level1 35
#property indicator_level2 64
#property indicator_level3 93


//---- input parameters
extern int       BBPeriod=55;
extern double    BBDevs=0.5; 
extern int       smPeriod=3; 
extern int       smMethod=0; 
//---- buffers
double body[];
double ushd[];
double lshd[];

double Buf4[];
double Buf5[];
double Buf6[];
double Buf7[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorBuffers(7);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buf4);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Buf7);   

   SetIndexBuffer(2,body);
   SetIndexBuffer(3,lshd);
   SetIndexBuffer(4,ushd);
   SetIndexBuffer(5,Buf5);
   SetIndexBuffer(6,Buf6);   

   SetIndexLabel(0,"CandlCode ICS");
   SetIndexLabel(1,"CandlCode ICS Smoothed");   
   IndicatorDigits(0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    limit=Bars-IndicatorCounted()-1;
      for(int i=limit;i>=0;i--){
         body[i]=MathAbs(Open[i]-Close[i]);
         lshd[i]=Close[i]-Low[i];
         if(Close[i]>=Open[i])lshd[i]=Open[i]-Low[i];
         ushd[i]=High[i]-Open[i];
         if(Close[i]>=Open[i])ushd[i]=High[i]-Close[i];         
      }
      for(i=limit;i>=0;i--){
         double ThBot_b=iMAOnArray(body,0,BBPeriod,0,1,i)-BBDevs*(iMAOnArray(body,0,BBPeriod,0,1,i)-iBandsOnArray(body,0,BBPeriod,1,0,MODE_LOWER,i));
         double ThBot_l=iMAOnArray(lshd,0,BBPeriod,0,1,i)-BBDevs*(iMAOnArray(lshd,0,BBPeriod,0,1,i)-iBandsOnArray(lshd,0,BBPeriod,1,0,MODE_LOWER,i));
         double ThBot_u=iMAOnArray(ushd,0,BBPeriod,0,1,i)-BBDevs*(iMAOnArray(ushd,0,BBPeriod,0,1,i)-iBandsOnArray(ushd,0,BBPeriod,1,0,MODE_LOWER,i));
         double ThTop_b=iMAOnArray(body,0,BBPeriod,0,1,i)+BBDevs*(-iMAOnArray(body,0,BBPeriod,0,1,i)+iBandsOnArray(body,0,BBPeriod,1,0,MODE_UPPER,i));
         double ThTop_l=iMAOnArray(lshd,0,BBPeriod,0,1,i)+BBDevs*(-iMAOnArray(lshd,0,BBPeriod,0,1,i)+iBandsOnArray(lshd,0,BBPeriod,1,0,MODE_UPPER,i));
         double ThTop_u=iMAOnArray(ushd,0,BBPeriod,0,1,i)+BBDevs*(-iMAOnArray(ushd,0,BBPeriod,0,1,i)+iBandsOnArray(ushd,0,BBPeriod,1,0,MODE_UPPER,i));

         double k1=0;
         if(Close[i]==Open[i])k1=1;
         double k2=48;
         if(ushd[i]>=lshd[i])k2=64;
         double k3=1;
         if(Close[i]==Open[i])k3=0;
         double k4=0;
         if(Close[i]>Open[i])k4=1;
         double k5=0;
         if(body[i]<=ThBot_b)k5=80;
         double k6=0;
         if(body[i]>ThBot_b && body[i]<=ThTop_b)k6=96;
         double k7=0;
         if(body[i]>ThTop_b)k7=112;
         double k8=0;
         if(Close[i]<Open[i])k8=1;
         double k9=0;
         if(body[i]<=ThBot_b)k9=32;
         double k10=0;
         if(body[i]>ThBot_b && body[i]<=ThTop_b)k10=16;
         double CandleCode_b=k1*k2+k3*(k4*(k5+k6+k7)+k8*(k9+k10));
   
 
         k1=0;
         if(lshd[i]==0)k1=3;
         k2=0;
         if(lshd[i]<ThBot_l && lshd[i]>0)k2=2;
         k3=0;
         if(lshd[i]>ThBot_l && lshd[i]<=ThTop_l && lshd[i]>0)k3=1;
         double CandleCode_l=k1+k2+k3;

 
         k1=0;
         if(ushd[i]>0 && ushd[i]<=ThBot_u)k1=4;
         k2=0;
         if(ushd[i]>ThBot_u && ushd[i]<=ThTop_u)k2=8;
         k3=0;
         if(ushd[i]>ThTop_u)k3=12;
         double CandleCode_u=k1+k2+k3;

 
         double CandlCode=CandleCode_b+CandleCode_l+CandleCode_u;
         Buf4[i]=CandlCode;

      }  
      for(i=limit;i>=0;i--){
         Buf5[i]=iMAOnArray(Buf4,0,smPeriod,0,smMethod,i);
      }      
      for(i=limit;i>=0;i--){
         Buf6[i]=iMAOnArray(Buf5,0,smPeriod,0,smMethod,i);
      }        
      for(i=limit;i>=0;i--){
         Buf7[i]=iMAOnArray(Buf6,0,smPeriod,0,smMethod,i);
      }        
      
          
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments