Author: Copyright � 2006, raff1410@o2.pl
Trix

This indicator is designed to analyze price momentum by smoothing out market volatility and calculating the rate of change in a trend. It provides visual data on a separate window, allowing traders to identify potential entry points based on crossovers between a primary trend line and a secondary signal line.

Core Logic and Processing

The script operates through a multi-layered calculation process to filter out "noise" from the raw market price:

  • Initial Smoothing: The tool begins by taking the closing prices and applying a Smooth Moving Average (SMMA). This helps stabilize the data so that minor, insignificant price fluctuations do not trigger false readings.
  • Secondary Smoothing: It then takes that smoothed data and applies another layer of smoothing. This creates a refined baseline that represents the core trend of the asset.
  • Rate of Change Calculation: The core logic calculates the percentage difference between consecutive points on this refined baseline. This transforms the data into a "momentum" value—essentially showing how fast the price is moving in a specific direction.
  • Signal Line Generation: Finally, a "Signal Line" is created by applying an Exponential Moving Average (EMA) to the momentum values. This provides a secondary reference point to compare against the primary momentum line.

Visual Components

The indicator populates the chart with several distinct elements to help the user interpret the data:

  • Main Lines: Two primary lines represent the calculated momentum and the signal line. Their interaction is the primary focus for the trader.
  • Histogram: A visual representation of the distance between the momentum and the signal line, highlighting the strength of the current move.
  • Alert Arrows: The script identifies specific "crossover" points where the lines intersect. When the momentum line crosses above or below the signal line, it generates visual arrows on the chart to highlight these shifts in trend direction.

Automated Notifications

For active traders, the script includes an automated alert system. It monitors the very latest data point for a crossover:

  • Buy Signal: Triggered when the momentum line moves from below to above the signal line.
  • Sell Signal: Triggered when the momentum line moves from above to below the signal line.

To prevent repetitive notifications, the script includes a "state memory" logic that ensures it only sends one alert per trend change, rather than alerting on every single tick of data.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
14 Views
0 Downloads
0 Favorites
Trix
//+------------------------------------------------------------------+
//|                                                         TRIX.mq4 |
//|                                                          by Raff | 
//|                                                                  | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2006, raff1410@o2.pl"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1 Red
#property  indicator_color2 DeepSkyBlue
#property  indicator_color3 Yellow
#property  indicator_color4 Aqua
#property  indicator_color5 DarkGray
#property  indicator_color6 DarkGray
#property  indicator_width1 1
#property  indicator_width2 1
#property  indicator_width3 0
#property  indicator_width4 0
#property  indicator_width5 1
#property  indicator_width6 1
#property  indicator_style1 STYLE_SOLID
#property  indicator_style2 STYLE_DOT
#property  indicator_style3 STYLE_SOLID
#property  indicator_style4 STYLE_SOLID
#property  indicator_style5 STYLE_SOLID
#property  indicator_style6 STYLE_SOLID


#property  indicator_level1 0

//---- indicator parameters
extern int  TRIX_Period     = 13;
extern int  Signal_Period = 8;
extern bool Signals      = true;
extern int  CountBars    = 1500;

//---- indicator buffers
double      ind_buffer1[];
double      ind_buffer2[];
double      ind_buffer3[];
double      ind_buffer4[];
double      ind_buffer5[];
double      ind_buffer6[];
double      ind_buffer7[];

//---- variables
static bool TurnedUp = false;
static bool TurnedDown = false;  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorBuffers(7);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,233);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,234);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_HISTOGRAM);

//---- indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);
   SetIndexBuffer(3,ind_buffer4);
   SetIndexBuffer(4,ind_buffer5);
   SetIndexBuffer(5,ind_buffer6);
   SetIndexBuffer(6,ind_buffer7);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("TRIX index | Period: "+TRIX_Period+", Signal Period: "+Signal_Period+" | ");
   SetIndexLabel(0,"TRIX");
   SetIndexLabel(1,"Signal");

//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| TRIX                                                             |
//+------------------------------------------------------------------+
int start()
  {
   if (TRIX_Period==Signal_Period) return(0);
   
   int i, limit=CountBars;
   if (limit>Bars) limit=Bars-1;

//---- trix 
   for(i=0; i<limit; i++) ind_buffer1[i]=iMA(NULL,0,TRIX_Period,0,MODE_SMMA,PRICE_CLOSE,i);
   for(i=0; i<limit; i++) ind_buffer2[i]=iMAOnArray(ind_buffer1,0,TRIX_Period,0,MODE_SMMA,i);
   for(i=0; i<limit; i++) ind_buffer7[i]=iMAOnArray(ind_buffer2,0,TRIX_Period,0,MODE_EMA,i);
   
   for(i=0; i<limit-1; i++) ind_buffer1[i]=(ind_buffer7[i]-ind_buffer7[i+1])/ind_buffer7[i+1];
   for(i=0; i<limit-1; i++) ind_buffer2[i]=iMAOnArray(ind_buffer1,0,Signal_Period,0,MODE_EMA,i);
   for(i=0; i<limit-1; i++) {ind_buffer5[i]=ind_buffer1[i]-ind_buffer2[i]; ind_buffer6[i]=ind_buffer5[i];}

//---- signals
   i=limit-1;
   while(i>=0)
   {
     if (Signals==true)
     {
     if (ind_buffer2[i]<ind_buffer1[i] && ind_buffer2[i+1]>=ind_buffer1[i+1]) ind_buffer3[i]=ind_buffer2[i]-0.0001;
     if (ind_buffer2[i]>ind_buffer1[i] && ind_buffer2[i+1]<=ind_buffer1[i+1]) ind_buffer4[i]=ind_buffer2[i]+0.0001;
     
     if (ind_buffer3[0]==ind_buffer2[0]-0.0001 && TurnedUp==false)
        {  
              Alert("Trix Buy:  ",Symbol()," - ",Period(),"  at  ", Close[0],"  -  ", TimeToStr(CurTime(),TIME_SECONDS));
              TurnedDown = false;
              TurnedUp = true;
        } 
     if (ind_buffer4[0]==ind_buffer2[0]+0.0001 && TurnedDown==false)
        {  
              Alert("Trix SELL:  ",Symbol()," - ",Period(),"  at  ", Close[0],"  -  ", TimeToStr(CurTime(),TIME_SECONDS));
              TurnedUp = false;
              TurnedDown = true;
        } 
     }
   i--;
   }
//---- done
   return(0);
  }

Comments