tcf smoothed - T3

Download script
Author: mladen
tcf smoothed - T3

This script functions as a technical analysis tool designed to measure and visualize the strength of market trends. Based on the "Trend Continuation Factor" (TCF) methodology, its primary purpose is to help traders identify whether a current price movement has sufficient momentum to continue or if it is losing steam.

Core Logic Overview

The indicator operates by breaking down price movements into two distinct components: upward pressure and downward pressure. Instead of simply looking at where the price is, it focuses on the velocity and accumulation of those movements over a specific period.

1. Movement Analysis (Rate of Change) The script first calculates the "Rate of Change" by comparing the current moving average of the price to the previous one. This identifies the immediate direction of the market.

  • If the price is moving up, it records the positive momentum.
  • If the price is moving down, it records the negative momentum.

2. Momentum Accumulation Rather than looking at these movements in isolation, the logic "stacks" or accumulates these values. It keeps a running total of the bullish and bearish forces. This allows the indicator to distinguish between a small, fleeting price tick and a sustained, heavy move that builds power over time.

3. Trend Continuation Calculation The tool then performs a specific calculation by comparing the accumulated upward strength against the accumulated downward strength over a user-defined timeframe (the "Length"). By subtracting the opposing force from the dominant force, it produces a clearer picture of which side of the market is currently in control.

4. Smoothing and Refinement (The T3 Filter) To ensure the data is readable and not "noisy," the script applies a sophisticated smoothing technique known as a T3 filter. This mathematical process takes the raw trend data and rounds off sharp edges without introducing the significant time delays often found in standard moving averages. This ensures that the visual output responds quickly to real-time market changes while remaining smooth enough for the human eye to follow easily.

Visual Output

The result is displayed in a separate window as two distinct lines:

  • The Bullish Line: Represents the smoothed strength of upward price continuation.
  • The Bearish Line: Represents the smoothed strength of downward price continuation.

By observing the height and direction of these lines, users can better visualize whether a trend is gaining "fuel" or beginning to exhaust itself.

Indicators Used
Moving average indicator
10 Views
0 Downloads
0 Favorites
tcf smoothed - T3
//+------------------------------------------------------------------+
//|                                                 tcf smoothed.mq4 |
//|                                                           mladen |
//|                                                                  |
//| Trend Continuation Factor originaly developed by M.H. Pee        |
//| TASC : 20:3 (March 2002) article                                 |
//| "Just How Long Will A Trend Go On? Trend Continuation Factor"    |
//+------------------------------------------------------------------+

#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Red

//

extern int    Length      = 7;//35
extern int    Price       = PRICE_CLOSE;
extern int    T3Period    = 7;//8
extern double T3Hot       = 0.1;//0.7
extern bool   T3Original  = false;

//
double TcfUp[];
double TcfDo[];
double values[][16];
double alpha;
double c1;
double c2;
double c3;
double c4;

//+------------------------------------------------------------------+


int init()
{
   SetIndexBuffer(0,TcfUp);
   SetIndexBuffer(1,TcfDo);
   
   //
  
      double a  = T3Hot;
             c1 = -a*a*a;
             c2 =  3*(a*a+a*a*a);
             c3 = -3*(2*a*a+a+a*a*a);
             c4 = 1+3*a+a*a*a+3*a*a;

      T3Period = MathMax(1,T3Period);
      if (T3Original)
           alpha = 2.0/(1.0 + T3Period);
      else alpha = 2.0/(2.0 + (T3Period-1.0)/2.0);

   //
    
   return(0);
}
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+

#define plus_ch   0
#define minus_ch  1
#define plus_cf   2
#define minus_cf  3
#define start_sup 4
#define start_sdo 10

//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,r,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;
         if (ArrayRange(values,0) != Bars) ArrayResize(values,Bars);

   //

   for(i=limit, r=Bars-limit-1; i>=0; i--,r++)
   {
      values[r][plus_ch]  = 0;
      values[r][minus_ch] = 0;
      values[r][plus_cf]  = 0;
      values[r][minus_cf] = 0;
         double plusTcf   = 0;
         double minusTcf  = 0;
         double roc       = iMA(NULL,0,1,0,MODE_SMA,Price,i)-iMA(NULL,0,1,0,MODE_SMA,Price,i+1);

         //
         
            if (roc>0)
               {
                  values[r][plus_ch] = roc;
                  values[r][plus_cf] = roc;
                     if (r>1) values[r][plus_cf] += values[r-1][plus_cf];
               }                  
            if (roc<0)
               {
                  values[r][minus_ch] = -roc;
                  values[r][minus_cf] = -roc;
                     if (r>1) values[r][minus_cf] += values[r-1][minus_cf];
               }
            for (int l=0; l<Length; l++)
               {
                  plusTcf  += values[r-l][plus_ch]-values[r-l][minus_cf];
                  minusTcf += values[r-l][minus_ch]-values[r-l][plus_cf];
               }
         
         //
         if (T3Period>1)
               { TcfUp[i] = iT3(plusTcf ,r,start_sup); TcfDo[i] = iT3(minusTcf,r,start_sdo);  }               
         else  { TcfUp[i] = plusTcf;                   TcfDo[i] = minusTcf;                   }               
   }      
   return(0);
}


//+------------------------------------------------------------------+

double iT3(double price,int i,int s)
{
   if (i < 1)
      {
         values[i][s+0] = price;
         values[i][s+1] = price;
         values[i][s+2] = price;
         values[i][s+3] = price;
         values[i][s+4] = price;
         values[i][s+5] = price;
      }
   else
      {
         values[i][s+0] = values[i-1][s+0]+alpha*(price         -values[i-1][s+0]);
         values[i][s+1] = values[i-1][s+1]+alpha*(values[i][s+0]-values[i-1][s+1]);
         values[i][s+2] = values[i-1][s+2]+alpha*(values[i][s+1]-values[i-1][s+2]);
         values[i][s+3] = values[i-1][s+3]+alpha*(values[i][s+2]-values[i-1][s+3]);
         values[i][s+4] = values[i-1][s+4]+alpha*(values[i][s+3]-values[i-1][s+4]);
         values[i][s+5] = values[i-1][s+5]+alpha*(values[i][s+4]-values[i-1][s+5]);
      }
   return(c1*values[i][s+5] + c2*values[i][s+4] + c3*values[i][s+3] + c4*values[i][s+2]);
}

Comments