Pretty_T3_RSI_LK_V1.0

Download script
Author: Copyright � 2009, Leif Karlsson
Pretty_T3_RSI_LK_V1.0

This technical indicator is designed to provide traders with a smoothed, visual representation of market momentum and trend direction. It combines two well-known analytical concepts—the Relative Strength Index (RSI) and the T3 Moving Average—to create a unique tool that highlights whether a price movement is gaining strength or losing steam.

Core Logic Overview

The script functions by processing price data through several layers of calculation to filter out "noise" while maintaining responsiveness. Here is the step-by-step logic:

1. Data Normalization (RSI Base) Instead of looking at raw price, the indicator starts with the Relative Strength Index (RSI). It takes the RSI value and shifts it so that the center point is zero. This allows the tool to measure "over-performance" or "under-performance" relative to a neutral baseline.

2. Smoothing via T3 Calculation The script then applies a specific type of moving average known as the T3. Unlike standard moving averages which can be "laggy" (reacting too slowly to price changes) or "jittery" (reacting too much to tiny fluctuations), the T3 uses a complex weighting system. This creates a very smooth line that follows the price trend closely without being distracted by minor market ripples.

3. Trend Intensity Analysis Beyond just showing a moving average, the script calculates the "strength" of the current trend. It looks at the rate of change between the T3 values and applies a mathematical formula (an exponential function) to determine how aggressive the movement is. This identifies whether a trend is accelerating, decelerating, or stabilizing.

Visual Output and User Experience

The script provides two distinct ways to view this information based on the user's preferences:

  • Dynamic Color Mode (RGB Mode): When enabled, the indicator line changes color dynamically. It uses the calculated "Trend Strength" to blend colors—typically shifting between blue and red. This gives the trader an immediate visual cue: one color represents upward momentum, while the other represents downward momentum.
  • Dual-Line Mode: If the color mode is turned off, the indicator splits into two separate lines (an "Up" line and a "Down" line). These appear when the T3 value moves higher or lower than its previous position, respectively, making it easier to see specific trend breaks.

Summary for the Trader

In simple terms, this tool tells you: "Where is the price momentum heading, and how strongly is it moving there?" It filters out the chaos of the market to show a clear, color-coded path of the underlying trend, helping traders identify when a move is gaining significant power or beginning to tire out.

Indicators Used
Relative strength index
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Pretty_T3_RSI_LK_V1.0
//+------------------------------------------------------------------+
//|                                        Pretty_t3_RSI_LK_V1.0.mq4 |
//|                         Orginal T3 calculation by Tim Tillson in |
//|     Technical Analysis of Stocks and Commodities - January 1998. |
//|                     Source code Copyright © 2009, Leif Karlsson. |
//|                                        Leffemannen1973@telia.com |
//+------------------------------------------------------------------+
//| Please feel free to copy, modify and / or redistribute this      |
//| software / source code in any way you see fit.                   |
//+------------------------------------------------------------------+
//+ ********************* Shameless Ad. **************************** +
//+ * I do custom programing jobs in Java, C, X86 Assembler & MQL4 * +
//+ ***** Pleace do not hesitate to get in contact if you nead ***** +
//+ ***** something special: EA, indicator or somthing else. ******* +
//+ ****************** Leffemannen1973@telia.com ******************* +
//+ **************************************************************** +
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Leif Karlsson"
#property link      "mailto://Leffemannen1973@telia.com"
//+------------------------------------------------------------------+
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_maximum 55
#property  indicator_minimum -55
//+------------------------------------------------------------------+
extern int RSIPeriod = 7;
extern int T3Period = 7;
extern double T3Amp = 1.3;
extern string AppliedPriceText1 = "Close: 0, Open: 1, High: 2, Low: 3";
extern string AppliedPriceText2 = "Median: 4, Typical: 5, Weighted: 6";
extern int AppliedPrice = 4;
extern int PriceShift = 0;
extern int MaxBars = 1000;
extern bool RGBMode = true;
extern int RGBLineWidth = 2;
//+------------------------------------------------------------------+
// Index Buffers
double UpBuffer[];	// Up trend buffer (only used then RGBMode = false)
double DwBuffer[];	// Down trend buffer (only used then RGBMode = false)
double t3[]; 		// Main T3 value (always used)
double Trend[]; 		// Primitive trend filter (max 1, min -1): InvFisher(0.5*Sqrt(T3Period)*[T3 Rate of change] / ATR) (always used)

// Used for T3 calc
double c1;
double c2;
double c3;
double c4;

// "Fake" Index Buffers, advance forward using ArrayCopy
double p1[];
double p2[];
double p3[];
double p4[];
double p5[];
double p6[];

// T3 Alpha (weight)
double Alpha;

string IndiName;
bool FirstRun;
datetime LastTime = 0;
//+------------------------------------------------------------------+
int deinit() {

	int i = MaxBars;
	while(i >= 0 && RGBMode) {
		ObjectDelete(IndiName + i);
		i--;
	}
	return(0);
}
//+------------------------------------------------------------------+
int init() {
	// Index Buffers
	IndicatorBuffers(4);	
			
   	SetIndexStyle(0, DRAW_LINE);
   	SetIndexStyle(1, DRAW_LINE);
	
   	SetIndexBuffer(0, UpBuffer);
   	SetIndexBuffer(1, DwBuffer);	
   	SetIndexBuffer(2, t3);	
   	SetIndexBuffer(3, Trend);
   	// 
   	
   	// "Fake" Index Buffers   	
	ArrayResize(p1, MaxBars+1);
	ArrayResize(p2, MaxBars+1);
	ArrayResize(p3, MaxBars+1);
	ArrayResize(p4, MaxBars+1);
	ArrayResize(p5, MaxBars+1);
	ArrayResize(p6, MaxBars+1);
		
	ArraySetAsSeries(p1, true);
	ArraySetAsSeries(p2, true);
	ArraySetAsSeries(p3, true);
	ArraySetAsSeries(p4, true);
	ArraySetAsSeries(p5, true);
	ArraySetAsSeries(p6, true); 
	//
	
	IndiName = "T3 RSI, T3Period: " + T3Period + ", RSIPeriod: " + RSIPeriod + ", PriceShift: " + PriceShift + " ";
   	IndicatorShortName(IndiName);
   	
   	Alpha = 2.0/(T3Period + 1.0);  

	// Pre calc some T3 values   	
   	double a = T3Amp;
   	c1 = -a*a*a;
	c2 = 3.0*a*a + 3.0*a*a*a;
	c3 = -6.0*a*a - 3.0*a - 3.0*a*a*a;
	c4 = 1.0 + 3.0*a + a*a*a + 3.0*a*a;
	//

	FirstRun = true;
   	 	
   	return(0);
}
//+------------------------------------------------------------------+
void Draw(double Val[], int i, color c) {
	
	string ObjName = IndiName + (Time[i]/(60*Period())) % MaxBars;
	
	static int WindowNr = -1;
	if(WindowNr < 0) WindowNr = WindowFind(IndiName);
	
      ObjectDelete(ObjName);
      ObjectCreate(ObjName, OBJ_TREND, WindowNr, Time[i+1], Val[i+1], Time[i], Val[i]);
      ObjectSet(ObjName, OBJPROP_RAY, false);
      ObjectSet(ObjName, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(ObjName, OBJPROP_COLOR, c);        
      ObjectSet(ObjName, OBJPROP_WIDTH, RGBLineWidth);
}
//+------------------------------------------------------------------+
int start() {

	int i = IndicatorCounted();
	if(i < 0) return(-1);
	i = Bars - i;
	if(i > MaxBars) i = MaxBars;
	if(FirstRun || i == MaxBars) {
		FirstRun = false;
		LastTime = Time[0];
						
		p1[i] = iRSI(NULL, 0, RSIPeriod, AppliedPrice,i+PriceShift)-50.0;
		p2[i] = p1[i];
		p3[i] = p1[i];
		p4[i] = p1[i];
		p5[i] = p1[i];
		p6[i] = p1[i];
		t3[i] = p1[i];
		i--;
	} 
	else {
		int j = ArrayBsearch(Time, LastTime, MaxBars, 0, MODE_DESCEND);
		if(j > 0) {
			ArrayCopy(p1, p1, j, 0, ArraySize(p1)-j);
			ArrayCopy(p2, p2, j, 0, ArraySize(p2)-j);
			ArrayCopy(p3, p3, j, 0, ArraySize(p3)-j);
			ArrayCopy(p4, p4, j, 0, ArraySize(p4)-j);
			ArrayCopy(p5, p5, j, 0, ArraySize(p5)-j);
			ArrayCopy(p6, p6, j, 0, ArraySize(p6)-j);
		}
		LastTime = Time[0];
	}
					
	while(i >= 0) {
		
		// Main T3 calc
		double p0 = iRSI(NULL, 0, RSIPeriod, AppliedPrice,i+PriceShift)-50.0;
		p1[i] = p1[i+1] + Alpha*(p0 - p1[i+1]);
		p2[i] = p2[i+1] + Alpha*(p1[i] - p2[i+1]);
		p3[i] = p3[i+1] + Alpha*(p2[i] - p3[i+1]);
		p4[i] = p4[i+1] + Alpha*(p3[i] - p4[i+1]);
		p5[i] = p5[i+1] + Alpha*(p4[i] - p5[i+1]);
		p6[i] = p6[i+1] + Alpha*(p5[i] - p6[i+1]);
						
		t3[i] = c1*p6[i] + c2*p5[i] + c3*p4[i] + c4*p3[i];
		//
		
		// Trend strength calc
		Trend[i] = MathSqrt(T3Period)*(t3[i]-t3[i+1])/(T3Amp*10.0);
		Trend[i] = ((1.0-MathExp(-2.0*Trend[i]))/(1.0+MathExp(-2.0*Trend[i])));
		//
		
		if(RGBMode) {
			int b = 127.0 + 127.0*Trend[i];
			int r = 127.0 - 127.0*Trend[i];
			Draw(t3, i, b << 16 + r);
		} 
		if(!RGBMode && t3[i] > t3[i+1]) {
			UpBuffer[i] = t3[i];
			DwBuffer[i] = EMPTY_VALUE;
			if(UpBuffer[i+1] == EMPTY_VALUE) UpBuffer[i+1] = t3[i+1];
		}
		if(!RGBMode && t3[i] < t3[i+1]) {
			DwBuffer[i] = t3[i];
			UpBuffer[i] = EMPTY_VALUE;
			if(DwBuffer[i+1] == EMPTY_VALUE) DwBuffer[i+1] = t3[i+1];
		}
						
		i--;
	}	

   	return(0);
}

Comments