T3 crosses
Download scriptThis tool is designed to help traders identify specific momentum shifts in the market by monitoring the interaction between two distinct moving averages. Instead of using standard lagging indicators, it utilizes a specialized mathematical smoothing technique known as the "T3" calculation.
Core Logic and Movement
The script creates two separate trend lines on your chart:
- The Fast Trend: This line reacts quickly to recent price changes. It is designed to capture immediate momentum.
- The Slow Trend: This line reacts more gradually, providing a broader view of the overall market direction.
By comparing these two lines against each other, the script identifies "crossovers"—moments where the short-term sentiment shifts from being above the long-term average to below it, or vice versa.
How It Identifies Signals
The primary purpose of this script is to provide visual alerts (arrows) on your chart when these two lines intersect:
- Bullish Signal (Buy/Green): When the Fast Trend line moves from below to above the Slow Trend line, the script places a green arrow. This suggests that upward momentum is accelerating relative to the broader trend.
- Bearish Signal (Sell/Red): When the Fast Trend line moves from above to below the Slow Trend line, the script places a red arrow. This suggests that downward momentum is taking hold.
Precision and Smoothing
Unlike basic moving averages that can be "choppy" and produce many false signals, this script uses complex weighting coefficients. These weights are calculated based on your chosen periods to ensure the lines remain smooth while still remaining responsive to price action.
Additionally, the script automatically places these signals at a distance from the candles (using market volatility data) to ensure the arrows are clearly visible and do not overlap with the price bars themselves.
//+------------------------------------------------------------------+
//| T3 crosses.mq4 |
//| mladen |
//| |
//| |
//| original T3 developed by Tim Tilson (TASC January 1998) |
//| period lag modification by Bob Fulks and Alex Matulich 4/2003 |
//+------------------------------------------------------------------+
#property copyright "copyleft mladen"
#property link "mladenfx@gmail.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//
//
//
//
//
extern int T3FastPeriod = 9;
extern int T3FastPrice = PRICE_CLOSE;
extern double T3FastHot = 1.0;
extern bool T3FastOriginal = true;
extern int T3SlowPeriod = 27;
extern int T3SlowPrice = PRICE_CLOSE;
extern double T3SlowHot = 0.5;
extern bool T3SlowOriginal = true;
//
//
//
//
//
double t3fast[];
double t3slow[];
double t3gCross[];
double t3rCross[];
double emas[][12];
double alphaFast,alphaSlow;
double c1fast,c1slow;
double c2fast,c2slow;
double c3fast,c3slow;
double c4fast,c4slow;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(4);
SetIndexBuffer(0,t3gCross); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,217);
SetIndexBuffer(1,t3rCross); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,218);
SetIndexBuffer(2,t3fast);
SetIndexBuffer(3,t3slow);
//
//
//
//
//
T3FastPeriod = MathMax(1,T3FastPeriod);
if (T3FastOriginal)
alphaFast = 2.0/(1.0 + T3FastPeriod);
else alphaFast = 2.0/(2.0 + (T3FastPeriod-1.0)/2.0);
double a = T3FastHot;
c1fast = -a*a*a;
c2fast = 3*a*a+3*a*a*a;
c3fast = -6*a*a-3*a-3*a*a*a;
c4fast = 1+3*a+a*a*a+3*a*a;
//
//
//
//
//
T3SlowPeriod = MathMax(1,T3SlowPeriod);
if (T3SlowOriginal)
alphaSlow = 2.0/(1.0 + T3SlowPeriod);
else alphaSlow = 2.0/(2.0 + (T3SlowPeriod-1.0)/2.0);
a = T3SlowHot;
c1slow = -a*a*a;
c2slow = 3*a*a+3*a*a*a;
c3slow = -6*a*a-3*a-3*a*a*a;
c4slow = 1+3*a+a*a*a+3*a*a;
//
//
//
//
//
IndicatorShortName("T3 crosses ("+T3FastPeriod+","+T3SlowPeriod+")");
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if (ArrayRange(emas,0) != Bars) ArrayResize(emas,Bars);
//
//
//
//
//
for(i=limit; i>=0; i--)
{
t3fast[i] = iT3(iMA(NULL,0,1,0,MODE_SMA,T3FastPrice,i),i,0,alphaFast,c1fast,c2fast,c3fast,c4fast);
t3slow[i] = iT3(iMA(NULL,0,1,0,MODE_SMA,T3SlowPrice,i),i,6,alphaSlow,c1slow,c2slow,c3slow,c4slow);
t3gCross[i] = EMPTY_VALUE;
t3rCross[i] = EMPTY_VALUE;
//
//
//
//
//
if (t3fast[i] > t3slow[i] && t3fast[i+1] < t3slow[i+1]) t3gCross[i] = Low[i] -iATR(NULL,0,20,i);
if (t3fast[i] < t3slow[i] && t3fast[i+1] > t3slow[i+1]) t3rCross[i] = High[i]+iATR(NULL,0,20,i);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double iT3(double price,int shift,int startBuff,double alpha,double c1,double c2,double c3,double c4)
{
int i = Bars-shift-1;
if (i < 1)
{
emas[i][startBuff+0] = price;
emas[i][startBuff+1] = price;
emas[i][startBuff+2] = price;
emas[i][startBuff+3] = price;
emas[i][startBuff+4] = price;
emas[i][startBuff+5] = price;
}
else
{
emas[i][startBuff+0] = emas[i-1][startBuff+0]+alpha*(price -emas[i-1][startBuff+0]);
emas[i][startBuff+1] = emas[i-1][startBuff+1]+alpha*(emas[i][startBuff+0]-emas[i-1][startBuff+1]);
emas[i][startBuff+2] = emas[i-1][startBuff+2]+alpha*(emas[i][startBuff+1]-emas[i-1][startBuff+2]);
emas[i][startBuff+3] = emas[i-1][startBuff+3]+alpha*(emas[i][startBuff+2]-emas[i-1][startBuff+3]);
emas[i][startBuff+4] = emas[i-1][startBuff+4]+alpha*(emas[i][startBuff+3]-emas[i-1][startBuff+4]);
emas[i][startBuff+5] = emas[i-1][startBuff+5]+alpha*(emas[i][startBuff+4]-emas[i-1][startBuff+5]);
}
return(c1*emas[i][startBuff+5] + c2*emas[i][startBuff+4] + c3*emas[i][startBuff+3] + c4*emas[i][startBuff+2]);
}
Comments