TSI Signals
Download scriptThis script is designed as a visual trading tool that automatically identifies potential entry points in the financial markets by analyzing price momentum. Rather than requiring you to manually interpret complex charts, it acts as an automated "alert system" that places visual markers directly on your screen to highlight specific trends.
How the Logic Works
The core of this script relies on a mathematical concept called the True Strength Index (TSI). This is a momentum indicator used to determine whether a market is moving with strength or if it is beginning to exhaust itself.
To provide more accurate signals and reduce "noise" (false signals), the script performs three main steps:
1. Data Processing The script looks at the price history of the asset you are trading. It calculates two specific values simultaneously:
- The TSI Line: Represents the primary momentum of the market.
- The Signal Line: A smoothed version of that momentum, which helps distinguish between a temporary fluctuation and a genuine trend change.
2. The "Crossover" Detection The script constantly compares these two lines against each other on every new price movement. It is looking for a specific interaction known as a "crossover":
- Bullish Signal: When the primary momentum line moves from below the signal line to above it, it suggests that upward momentum is gaining strength.
- Bearish Signal: When the primary momentum line moves from above the signal line to below it, it suggests that downward momentum is taking over.
3. Visual Execution Once the script identifies one of these crossovers, it automatically draws an arrow on your chart:
- Upward Arrows: These appear at the price level when the data suggests a shift toward an upward trend.
- Downward Arrows: These appear when the data suggests a shift toward a downward trend.
User Experience
From a user's perspective, you do not need to watch the underlying math or plot the oscillators yourself. The script handles all calculations in the background and simplifies the entire process into a visual cue. You simply look for the arrows to appear on your chart, which serve as your primary indicators for when the market momentum has shifted in a specific direction.
//+------------------------------------------------------------------+
//| TSI Signals.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_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 MediumBlue
//---- input parameters
extern int First_R=8;
extern int Second_S=5;
extern int SignalPeriod=5;
extern int Mode_Smooth=1;
extern int ArrowShift=5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,217);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0,"UpArrow");
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,218);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(1,"DownArrow");
SetIndexEmptyValue(1,0.0);
//----
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;
double curTSI=0.0,prevTSI=0.0,curSignal=0.0,prevSignal=0.0;
limit=Bars-counted_bars-First_R-Second_S-SignalPeriod;
for (i=limit;i>=0;i--)
{
curTSI=iCustom(NULL,0,"TSI-Osc",First_R,Second_S,SignalPeriod,Mode_Smooth,0,i);
prevTSI=iCustom(NULL,0,"TSI-Osc",First_R,Second_S,SignalPeriod,Mode_Smooth,0,i+1);
curSignal=iCustom(NULL,0,"TSI-Osc",First_R,Second_S,SignalPeriod,Mode_Smooth,1,i);
prevSignal=iCustom(NULL,0,"TSI-Osc",First_R,Second_S,SignalPeriod,Mode_Smooth,1,i+1);
if ((curTSI>curSignal)&&(prevTSI<prevSignal)) ExtMapBuffer1[i]=Close[i]+3*ArrowShift*Point;
if ((curTSI<curSignal)&&(prevTSI>prevSignal)) ExtMapBuffer2[i]=Close[i]-ArrowShift*Point;
}
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
Comments