This script is designed to function as a specialized technical analysis tool for trading platforms. Its primary purpose is to visualize and smooth out market momentum to help traders identify trends more clearly.
Core Logic Overview
The script operates by layering three distinct levels of data processing. Instead of showing raw price action, it transforms the data through several mathematical "filters" to reduce market noise and highlight underlying movements.
1. The Foundation (TSI-Osc Basis) The logic begins by pulling data from an existing momentum oscillator called "TSI-Osc." It looks at this base data to understand the current strength of a price move. This serves as the raw material for all subsequent calculations.
2. The First Smoothing Layer (Ergodic Component) Once the basic momentum data is captured, the script applies an Exponential Moving Average (EMA) to it. In practical terms, this acts as a "smoothing" agent. By averaging the data over a specific period, it removes minor, jagged price fluctuations that might otherwise lead to false signals, creating a more stable trend line.
3. The Secondary Smoothing Layer (Signal Component) To achieve maximum stability and clarity, the script performs a second round of smoothing. It takes the result of the first smoothing layer and applies another Exponential Moving Average to it. This final step produces a "Signal" line.
Visual Representation
On your trading chart, this logic results in two distinct lines:
- The Ergodic Line: A primary trend indicator that shows the smoothed momentum of the market.
- The Signal Line: A secondary line that follows the Ergodic line but moves more slowly and smoothly.
How to Interpret the Results
By using two layers of smoothing on top of a momentum oscillator, the script aims to provide a "clean" look at the market's direction. Traders typically look for the relationship between these two lines—specifically when they cross one another or diverge significantly—as an indication of potential changes in market momentum. The inclusion of specific horizontal levels (such as 20 and -20) helps traders identify periods of extreme overextension or strength.
//+------------------------------------------------------------------+
//| TSI.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_level1 0
#property indicator_level2 20
#property indicator_level3 -20
//---- input parameters
extern int First_R=8;
extern int Second_S=5;
extern int SignalPeriod=5;
extern int Mode_Smooth=1;
//---- buffers
double ErgodicBuffer[];
double Signal_Buffer[];
double TSI_Siganl_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(3);
SetIndexBuffer(2, TSI_Siganl_Buffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ErgodicBuffer);
SetIndexLabel(0,"Ergodic");
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Signal_Buffer);
SetIndexLabel(1,"Signal");
IndicatorShortName("Ergodic Osc"+"("+First_R+","+Second_S+","+SignalPeriod+")");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;
limit=Bars-counted_bars-1;
for (i=limit;i>=0;i--)
{
TSI_Siganl_Buffer[i]=iCustom(NULL,0,"TSI-Osc",First_R,Second_S,SignalPeriod,Mode_Smooth,1,i);
}
for (i=limit;i>=0;i--)
{
ErgodicBuffer[i]=iMAOnArray(TSI_Siganl_Buffer,0,5,0,MODE_EMA,i);
}
for (i=limit;i>=0;i--)
{
Signal_Buffer[i]=iMAOnArray(ErgodicBuffer,0,5,0,MODE_EMA,i);
}
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
Comments