TRIX-with-alert

Download script
Author: Lightning Signals
TRIX-with-alert

This tool is a specialized technical analysis indicator designed to help traders identify momentum shifts and trend reversals in the financial markets. It works by analyzing the "speed" of price movement rather than just the price itself, helping to smooth out market noise and provide clearer signals for entry or exit points.

Core Logic and Mechanics

The script functions through a multi-layered smoothing process. Instead of calculating data from the raw price directly, it passes the information through three successive stages of "Exponential Moving Averages" (EMA).

  1. Triple Smoothing: The tool takes the current market price and calculates an average. It then applies a second average to that first result, and a third average to that second result. This triple-layering effectively filters out minor fluctuations and "fake" price movements, leaving behind a much smoother representation of the underlying trend.
  2. Momentum Calculation: Once these three smoothed layers are established, the script calculates the percentage difference between the most recent value and the previous value. This calculation represents the momentum—essentially showing how fast or slow the price trend is accelerating or decelerating.
  3. The Signal Line: To make the momentum data easier to read, the script creates a "Signal" line. This is a Simple Moving Average of the momentum itself. By comparing the main momentum line against this signal line, traders can see when the current strength of a move is beginning to change.

Visual Representation and Alerts

The indicator appears in a separate window below your main chart as two distinct lines:

  • The TRIX Line: Represents the calculated momentum.
  • The Signal Line: Represents the average momentum over a specific period.

Automated Notifications

Beyond just providing a visual guide, the script includes an intelligent detection system for "crosses." When the TRIX line crosses over or under the Signal line, it indicates a potential change in market sentiment.

To ensure traders don't miss these key moments, the script can be configured to trigger two types of notifications:

  • Audio Alerts: A sound will play on your computer immediately when a crossover occurs.
  • Email Notifications: An automated email will be sent to your registered address, notifying you of the specific currency or asset and the timeframe where the trend shift took place.

By combining triple-smoothed data with automated alerts, this script aims to provide a more stable and reliable way to identify when a market trend is gaining strength or beginning to fade.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
TRIX-with-alert
//+------------------------------------------------------------------+
//|                                                         TRIX.mq4 |
//|                                                                  |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

#property copyright "Lightning Signals"
#property link "http://www.metaquotes.net"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Crimson
#property  indicator_width1  2
#property  indicator_width2  2
//---- input parameters
extern int TRIXPeriod = 4;
extern int TRIXSignal = 4 ;
extern int MAAppliedPrice = 0;
extern bool Email=true;
extern bool Sound=true;

// PRICE_CLOSE 0 Close price. 
// PRICE_OPEN 1 Open price. 
// PRICE_HIGH 2 High price. 
// PRICE_LOW 3 Low price. 
// PRICE_MEDIAN 4 Median price, (high+low)/2. 
// PRICE_TYPICAL 5 Typical price, (high+low+close)/3. 
// PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 



//extern int Desplazar = 1;
//---- buffers
double TRIX_Buffer[];
double Signal_Buffer[];
double EMA1_buffer[];
double EMA2_buffer[];
double EMA3_buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 3 additional buffers are used for counting.
IndicatorBuffers(5);
SetIndexBuffer(2,EMA1_buffer);
SetIndexBuffer(3,EMA2_buffer);
SetIndexBuffer(4,EMA3_buffer);

//---- indicators - drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TRIX_Buffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,TRIXSignal);
SetIndexBuffer(1,Signal_Buffer);


//---- name for DataWindow and indicator subwindow label
IndicatorShortName("TRIX("+TRIXPeriod+","+TRIXSignal+")");
SetIndexLabel(0,"Trix");
SetIndexLabel(1,"Signal");

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- 

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit;
int counted_bars=IndicatorCounted();

//---- check for possible errors
if(counted_bars<0) return(-1);

if(Bars<=TRIXPeriod) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=TRIXPeriod;i++) TRIX_Buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) Signal_Buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) EMA1_buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) EMA2_buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) EMA3_buffer[Bars-i]=0.0;
}

if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

for(i=0; i<limit; i++)
EMA1_buffer[i]=iMA(NULL,0,TRIXPeriod,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
EMA2_buffer[i]=iMAOnArray(EMA1_buffer,Bars,TRIXPeriod,0,MODE_EMA,i);
for(i=0; i<limit; i++)
EMA3_buffer[i]=iMAOnArray(EMA2_buffer,Bars,TRIXPeriod,0,MODE_EMA,i);

for(i=0; i<limit-1; i++)
   {
   TRIX_Buffer[i] = (EMA3_buffer[i] - EMA3_buffer[i+1]) / EMA3_buffer[i+1] *100;
   }

for(i=0; i<limit-1; i++)
   {
   Signal_Buffer[i]=iMAOnArray(TRIX_Buffer,Bars,TRIXSignal,0,MODE_SMA,i);
   }


Print(Crossed (TRIX_Buffer[0],Signal_Buffer[0]));



//---- done
return(0);
}


bool Crossed (double line1 , double line2 )
{

static string last_direction = "";
string current_dirction = "";

if(line1>line2)current_dirction = "up";
if(line1<=line2)current_dirction = "down";



if(current_dirction != last_direction) 
{
      if (Sound)
      {
         Alert("TRIX Cross for "+Symbol()+" on the "+Period()+" minute chart.");
      }
      if (Email)
      {
         SendMail ("TRIX Alert","Check TRIX for "+Symbol()+" on the "+Period()+" minute chart.");
      }
      last_direction = current_dirction;
      return (true);
}
else
{
      return (false);

}
 
} 


//+------------------------------------------------------------------+

Comments