Author: mladen
Trix tape

This script is a technical analysis tool designed to help traders visualize market momentum and price trends. Instead of showing you raw price data, it processes the market's movement through several layers of "smoothing" to filter out minor noise and highlight the underlying direction of the trend.

How the Logic Works

The indicator operates using a multi-stage calculation process:

1. Data Smoothing (Triple Exponential Moving Average) The script starts by taking the closing price of the assets and applying an Exponential Moving Average (EMA). It then takes that average and calculates another average on top of it, repeating this process a third time. This "triple smoothing" is designed to create a much more stable line that isn't easily distracted by sudden, temporary price spikes.

2. Momentum Calculation Once the data is smoothed, the script calculates the rate of change between the current smoothed value and the previous one. By measuring this difference as a percentage, the tool identifies how fast the price is moving in a specific direction. This represents the "momentum" of the market.

3. Signal Filtering To ensure the momentum readings are reliable, the script applies one final smoothing layer to the momentum data itself. This creates a "Signal Line," which helps differentiate between meaningful trend shifts and insignificant fluctuations.

Visual Representation: The "Tape"

The most unique feature of this script is how it displays information on your chart:

  • Dynamic Drawing: Rather than just showing you two static lines, the script draws a visual "tape." It compares the momentum value against the signal line to determine the trend's strength.
  • Color Coding: The script automatically detects whether the momentum is moving higher or lower relative to its signal. It then draws connected trend segments (lines) on your screen:
    • Green Lines: Indicate an upward momentum trend.
    • Red Lines: Indicate a downward momentum trend.
  • Real-Time Updates: The script constantly clears and redraws these segments as new price data comes in, ensuring that the "tape" always reflects the most recent market behavior.

Summary for the User

In simple terms, this tool looks at the "speed" of the price movement. It cleans up the messy price action into a smooth flow, identifies whether that flow is accelerating upward or downward, and draws a colored path (the tape) to show you exactly where that momentum is heading in real-time.

Indicators Used
Moving average indicatorMoving average indicator
15 Views
0 Downloads
0 Favorites
Trix tape
//+------------------------------------------------------------------+
//|                                                    Trix tape.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DimGray
#property indicator_color2 Lime

//
//
//
//
//

extern int   TrixPeriod    = 14;
extern int   SignalPeriod  = 14;
extern int   SignalMethod  =  3;
extern int   BarsToCount   = 300;
extern bool  ShowTape      = true;
extern color TapeColorUp   = Green;
extern color TapeColorDown = Red;
extern int   TapeBarsWidth = 1;

//
//
//
//
//

double TrixBuffer[];
double SignBuffer[];
double EmaBuffer1[];
double EmaBuffer2[];
double EmaBuffer3[];
string shortName;
int    Window;
int    WindowID;
int    Correction;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
   IndicatorBuffers(5);
   SetIndexBuffer(0,SignBuffer);
   SetIndexBuffer(1,TrixBuffer);
   SetIndexBuffer(2,EmaBuffer1);
   SetIndexBuffer(3,EmaBuffer2);
   SetIndexBuffer(4,EmaBuffer3);
   
   //
   //
   //
   //
   //

   Correction   = 3*TrixPeriod+SignalPeriod;
   WindowID     = MathRand();
   BarsToCount  = MathMax(BarsToCount,300);
   shortName    = "Trix tape("+TrixPeriod+","+SignalPeriod+" : "+WindowID+")";
   
   //
   //
   //
   //
   //
   
   IndicatorShortName(shortName);
   IndicatorDigits(5);
   return(0);
}

int deinit()
{
   DeleteTape();
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start()
{
   int    counted_bars=IndicatorCounted();
   int    limit,i;


   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit  = Bars-counted_bars;
         CheckWindow();

   //
   //
   //
   //
   //
      
   for (i=limit;i>=0;i--) EmaBuffer1[i] = iMA(NULL,0,TrixPeriod,0,MODE_EMA,PRICE_CLOSE,i);
   for (i=limit;i>=0;i--) EmaBuffer2[i] = iMAOnArray(EmaBuffer1,0,TrixPeriod,0,MODE_EMA,i);
   for (i=limit;i>=0;i--)
      {
         EmaBuffer3[i] = iMAOnArray(EmaBuffer2,0,TrixPeriod,0,MODE_EMA,i);

         //
         //
         //
         //
         //

         if (EmaBuffer3[i+1] != 0)
              TrixBuffer[i] = (EmaBuffer3[i]-EmaBuffer3[i+1])/EmaBuffer3[i+1];
         else TrixBuffer[i] = 0;
      }
   for (i=limit;i>=0;i--) SignBuffer[i] = iMAOnArray(TrixBuffer,0,SignalPeriod,0,SignalMethod,i);
   
   //
   //
   //
   //
   //
   
   DeleteTape();
   if (ShowTape) for (i=0; i<BarsToCount ;i++) DrawTape(TrixBuffer[i],SignBuffer[i],i);

   //
   //
   //
   //
   //
         
   for (i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-BarsToCount);
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#define SignalName "TrixTape"
    int maxLines = 0;

//
//
//
//
//

void DrawTape(double __1, double __2,int shift)
{
   if (__1==__2) return;
   
   //
   //
   //
   //
   //
   
   maxLines++;
      datetime time = Time[shift];
      string   name = StringConcatenate(SignalName,WindowID,"-",maxLines);
 
      ObjectCreate(name,OBJ_TREND,Window,time,__1,time,__2);
         if (__1>__2)
               ObjectSet(name,OBJPROP_COLOR ,TapeColorUp);
         else  ObjectSet(name,OBJPROP_COLOR ,TapeColorDown);
         ObjectSet(name,OBJPROP_RAY   ,false);
         ObjectSet(name,OBJPROP_BACK  ,true);
         ObjectSet(name,OBJPROP_WIDTH ,TapeBarsWidth);
}
void DeleteTape()
{
   string name = StringConcatenate(SignalName,WindowID);
      while(maxLines>0) { ObjectDelete(StringConcatenate(name,"-",maxLines)); maxLines--; }
                          ObjectDelete(name);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

void CheckWindow()
{
   string name = StringConcatenate(SignalName,WindowID);
   
   //
   //
   //
   //
   //
   
   Window = WindowFind(shortName);
   if(Window == -1) {
      Window = ObjectFind(name);
      if(Window == -1) {
         Window = WindowOnDropped();
            ObjectCreate(name,OBJ_TEXT,Window,0,0);
      }
   }
}

Comments