TRSI1
Download scriptThis custom trading indicator is designed to provide a smoothed and refined view of market momentum by layering multiple mathematical calculations on top of one another. Instead of looking at raw price data alone, it processes the information through several stages of "averaging" to filter out market noise and highlight significant trends.
How the Logic Works
The tool operates through a five-step sequence, where each step serves as the foundation for the next:
- The Foundation (RSI): The process begins by calculating a standard Relative Strength Index (RSI). This is a common momentum oscillator that measures how quickly an asset's price is rising or falling. In this script, it looks at the closing prices over a 14-period window to establish a baseline of market strength.
- The First Smoothing (EMA): To reduce sudden spikes in the RSI data, the script applies a 3-period Exponential Moving Average (EMA). This gives more weight to recent price action while smoothing out minor fluctuations.
- Layered Smoothing (Double EMA): The logic repeats this process twice more. It takes the result of the previous step and applies another 3-period EMA, then does it again. By stacking these three consecutive averages, the indicator significantly "muffles" erratic price movements, leaving behind a much cleaner trend line.
- The Primary Signal (Blue Line): The final result of those three layered averages is plotted on your chart as the blue line. This represents a highly refined version of the original RSI momentum.
- The Delayed Trend (Red Line): For the final layer, the script takes that refined blue line and applies a 5-period Simple Moving Average (SMA). Crucially, this specific calculation is "shifted" or displaced to the right by 3 bars. This creates the red line, which acts as a lagging confirmation of the trend, helping users visualize the direction of the momentum with a slight delay to confirm stability.
Visual Summary
- Gray Line: Represents the raw RSI data (the most reactive).
- Blue Line: Represents the "Triple EMA" processed version (the smoothed momentum).
- Red Line: Represents the final smoothed and shifted trend (the confirmation signal).
By moving from the raw data (Gray) to the heavily processed data (Red), the indicator allows you to see the underlying "flow" of the market while ignoring the daily distractions of minor price volatility.
//+------------------------------------------------------------------+
//| TRSI |
//| Copyright © 2007, Robert Hill |
//| http://www.metaquotes.net/ |
//| |
//| This is the formula from Mario:
//|
//| 1) RSI 14 period of close. Plot this as the gray line
//|
//| 2) 3-period exponential moving average of #1 above.
//|
//| 3) 3-period exponential moving average of #2 above.
//|
//| 4) 3-period exponential moving average of #3 above.
//| Plot this as the blue line.
//|
//| 5) 5-period simple moving average of #4 above
//| displaced 3 bars to the right.
//| Plot this as the red line.
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Robert Hill "
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Gray
#property indicator_color2 Aqua
#property indicator_color3 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
extern string r1=" 1. RSI(14) of Close";
extern string r2=" 2. EMA(3) of #1";
extern string r3=" 3. EMA(3) of #2";
extern string r4=" 4. EMA(3) of #3";
extern string r5=" 5. SMA(5) of #4";
extern string r6=" shifted right 3 bars";
extern int RSI_Period = 14;
extern string p = "--Applied Price Types--";
extern string p0 = " 0 = close";
extern string p1 = " 1 = open";
extern string p2 = " 2 = high";
extern string p3 = " 3 = low";
extern string p4 = " 4 = median(high+low)/2";
extern string p5 = " 5 = typical(high+low+close)/3";
extern string p6 = " 6 = weighted(high+low+close+close)/4";
extern int RSI_AppliedPrice = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int EMA1_Period = 3;
extern int EMA2_Period = 3;
extern int EMA3_Period = 3;
extern int SMA_Period = 5;
extern int SMA_Shift = 3;
extern bool PlotRSI = true;
extern bool PlotEMA3 = true;
extern bool PlotTRSI = true;
//---- buffers
double RSI[];
double EmaOfRSI[];
double EmaOfEmaOfRSI[];
double EmaOfEmaOfEmaOfRSI[];
double TRSI[];
double TempRSI[];
double TempEma3RSI[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexDrawBegin(0,RSI_Period);
IndicatorDigits(4);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,RSI) &&
!SetIndexBuffer(1,EmaOfEmaOfEmaOfRSI) &&
!SetIndexBuffer(2,TRSI) &&
!SetIndexBuffer(3,EmaOfRSI) &&
!SetIndexBuffer(4,EmaOfEmaOfRSI) &&
!SetIndexBuffer(5,TempRSI) &&
!SetIndexBuffer(6,TempEma3RSI))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
SetIndexLabel(0,"RSI");
SetIndexLabel(1,"TripleEmaOfRSI");
SetIndexLabel(2,"TRSI");
SetLevelStyle(STYLE_DOT, 1, Gray);
SetLevelValue(0, 30);
SetLevelValue(1, 50);
SetLevelValue(2, 70);
IndicatorShortName("TRSI("+RSI_Period+")");
//---- initialization done
return(0);
}
int start()
{
int i, limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars - RSI_Period;
// 1) RSI 14 period of close. Plot this as the gray line
for(i = limit; i >= 0; i--)
TempRSI[i] = iRSI(NULL,0,RSI_Period,RSI_AppliedPrice,i);
// 2) 3-period exponential moving average of #1 above.
for(i = limit; i >=0; i--)
EmaOfRSI[i] = iMAOnArray(TempRSI,Bars,EMA1_Period,0,MODE_EMA,i);
// 3) 3-period exponential moving average of #2 above.
for(i = limit; i >=0; i--)
EmaOfEmaOfRSI[i] = iMAOnArray(EmaOfRSI,Bars,EMA2_Period,0,MODE_EMA,i);
// 4) 3-period exponential moving average of #3 above.
for(i = limit; i >=0; i--)
TempEma3RSI[i] = iMAOnArray(EmaOfEmaOfRSI,Bars,EMA3_Period,0,MODE_EMA,i);
//========== COLOR CODING ===========================================
// 5) 5-period simple moving average of #4 above
// displaced 3 bars to the right.
for(i = limit; i >=0; i--)
{
if (PlotRSI) RSI[i] = TempRSI[i]; else RSI[i] = EMPTY_VALUE;
if (PlotEMA3) EmaOfEmaOfEmaOfRSI[i] = TempEma3RSI[i]; else EmaOfEmaOfEmaOfRSI[i] = EMPTY_VALUE;
if (PlotTRSI) TRSI[i] = iMAOnArray(TempEma3RSI,Bars,SMA_Period,SMA_Shift,MODE_SMA,i);
}
return(0);
}
//+------------------------------------------------------------------+
Comments