TSI_MACD
Download scriptThis tool is a custom technical analysis indicator designed to help traders visualize market momentum by combining two well-known trading concepts: the MACD (Moving Average Convergence Divergence) and the TSI (True Strength Index). Instead of looking at price directly, this script analyzes the "speed" and "strength" of price movements to identify potential trends.
Core Logic Breakdown
1. Measuring Momentum Changes The process begins by calculating the MACD, which measures the distance between two different moving averages. However, rather than showing the standard MACD value, this script specifically calculates the difference between consecutive MACD values. This essentially highlights how quickly the momentum is accelerating or decelerating from one moment to the next.
2. Analyzing Movement Intensity To understand the true strength of these momentum changes, the script calculates two distinct paths:
- Directional Flow: It tracks the actual movement (whether up or down).
- Absolute Strength: It calculates the "absolute" value of that movement, effectively stripping away the direction to focus solely on how volatile or powerful the move is, regardless of whether it is positive or negative.
3. Double Smoothing To ensure the data is readable and not distracted by "noise" (small, insignificant price flickers), the script applies a multi-layered smoothing process. It runs two consecutive rounds of Exponential Moving Averages (EMA) over both the directional flow and the absolute strength data. This refinement helps clarify the underlying trend by filtering out minor market irregularities.
4. The TSI Calculation The final core value is derived by comparing the smoothed directional flow against the smoothed absolute strength. By dividing the "direction" by the "total strength," the script produces a percentage-based oscillator.
- When the result moves toward the upper limit, it suggests that positive momentum is dominant compared to the overall volatility.
- When it moves toward the lower limit, it suggests that negative momentum is taking over.
5. The Signal Line Finally, the script generates a "Signal" line. This is a smoothed version of the final TSI calculation. Traders use this second line to identify turning points; when the main indicator crosses over this signal line, it often serves as a visual cue that the momentum may be shifting direction.
Summary for the User
In simple terms, this script acts as a "momentum filter." It takes raw price data, determines how fast it is moving, filters out the background noise through multiple smoothing layers, and then presents you with a clear visualization of whether the current trend has significant strength or if it is beginning to lose steam.
//+------------------------------------------------------------------+
//| TSI_MACD.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_maximum 110
#property indicator_minimum -110
#property indicator_level1 0
//---- input parameters
extern int Fast = 8;
extern int Slow = 21;
extern int Signal = 5;
extern int First_R = 8;
extern int Second_S = 5;
extern int SignalPeriod = 5;
extern int Mode_Smooth = 2;
//---- buffers
double TSI_Buffer[];
double SignalBuffer[];
double MTM_Buffer[];
double EMA_MTM_Buffer[];
double EMA2_MTM_Buffer[];
double ABSMTM_Buffer[];
double EMA_ABSMTM_Buffer[];
double EMA2_ABSMTM_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexBuffer(2, MTM_Buffer);
SetIndexBuffer(3, EMA_MTM_Buffer);
SetIndexBuffer(4, EMA2_MTM_Buffer);
SetIndexBuffer(5, ABSMTM_Buffer);
SetIndexBuffer(6, EMA_ABSMTM_Buffer);
SetIndexBuffer(7, EMA2_ABSMTM_Buffer);
//----
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, TSI_Buffer);
SetIndexLabel(0, "TSI_MACD");
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, SignalBuffer);
SetIndexLabel(1, "Signal");
IndicatorShortName("TSI_MACD(" + Fast + ", " + Slow + ", " + Signal + "; " +
First_R + ", " + Second_S + ", " + SignalPeriod + ")");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit, i;
limit = Bars - counted_bars - 1;
//----
for(i = Bars - 1; i >= 0; i--)
{
MTM_Buffer[i] = iMACD(NULL, 0, Fast, Slow, Signal, PRICE_CLOSE, MODE_MAIN, i - 1) -
iMACD(NULL, 0, Fast, Slow, Signal, PRICE_CLOSE, MODE_MAIN, i);
ABSMTM_Buffer[i] = MathAbs(MTM_Buffer[i]);
}
//----
for(i=Bars-1;i>=0;i--)
{
EMA_MTM_Buffer[i] = iMAOnArray(MTM_Buffer, 0, First_R, 0, MODE_EMA, i);
EMA_ABSMTM_Buffer[i] = iMAOnArray(ABSMTM_Buffer, 0, First_R, 0, MODE_EMA, i);
}
//----
for(i = Bars - 1; i >= 0; i--)
{
EMA2_MTM_Buffer[i] = iMAOnArray(EMA_MTM_Buffer, 0, Second_S, 0, MODE_EMA, i);
EMA2_ABSMTM_Buffer[i] = iMAOnArray(EMA_ABSMTM_Buffer, 0, Second_S, 0, MODE_EMA, i);
}
//----
for(i = limit; i >= 0; i--)
TSI_Buffer[i] = 100.0*EMA2_MTM_Buffer[i] / EMA2_ABSMTM_Buffer[i];
//----
for(i = limit; i >= 0; i--)
{
SignalBuffer[i] = iMAOnArray(TSI_Buffer, 0, SignalPeriod, 0, Mode_Smooth, i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments