TriggerLinesAlert

Download script
TriggerLinesAlert

The Trigger Line indicator is a technical analysis tool designed to help traders visualize market momentum and identify specific trend shifts by comparing two distinct mathematical moving averages. Rather than just showing raw price action, it creates a dedicated visual space (a separate window) to highlight the relationship between current price velocity and its smoothed average.

How the Logic Works

The indicator operates by calculating two primary components:

  1. The Weighted Momentum Line: The script analyzes a specific range of past prices (determined by the Rperiod setting). Unlike a standard moving average where every price is treated equally, this logic applies a "weighted" calculation. It gives more importance to certain data points within that period, creating a line that reacts dynamically to price changes while filtering out some of the "noise" found in raw market movement.

  2. The Smoothed Trend Line (LSMA): To provide context for the momentum line, the script calculates a Linear Standard Moving Average (LSMA). This acts as a secondary benchmark, smoothing out the fluctuations of the first line to reveal the broader underlying trend.

Visual Behavior and Interpretation

The core functionality of the indicator lies in how it displays these two lines on your chart:

  • Trend Identification: The script compares the Weighted Momentum Line against the Smoothed Trend Line.
  • Dynamic Visibility: To make the data easier to read at a glance, the indicator uses a specific coloring logic. When the momentum line is positioned above the smoothed trend line, it remains visible (typically appearing in blue). When the momentum line drops below the smoothed trend line, the script hides those specific data points (setting them to "Empty"), effectively highlighting only the periods where the momentum is positive relative to the average.
  • Color Transitions: This creates a visual cue where the lines appear to "trigger" or switch states based on whether the market is gaining strength or losing steam.

Automated Alerts

For traders who do not want to watch the charts constantly, the script includes an integrated notification system. If enabled, the logic monitors the crossover between these two lines in real-time:

  • Upward Trigger: When the momentum line crosses above the smoothed trend line, the system can trigger a visual alert and play a specific sound file.
  • Downward Trigger: Conversely, when the momentum line falls below the smoothed trend line, it triggers a different alert.

The script is designed to ensure these alerts only fire once per direction change, preventing repetitive notifications during a continuous trend move and only alerting you the moment a new trend "trigger" occurs.

Miscellaneous
Implements a curve of type %1It plays sound alerts
13 Views
0 Downloads
0 Favorites
TriggerLinesAlert
//+------------------------------------------------------------------+
//|                                                     Trigger Line |
//|                             Copyright © 2005 dwt5 and adoleh2000 |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005 dwt5 and adoleh2000 "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4            
#property indicator_color1 Red      
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int width;

extern bool Alerts = false;
extern int Rperiod = 15;
extern int LSMA_Period = 5;
int Draw4HowLong;
int shift;
int i;
int j;
int loopbegin;
int length;
int lsma_length;

double lengthvar;
double tmp ;
double tmp2 ;
double wt[];
double sum[];
double lsma_sum[];
double lsma_ma[];
double middle[];
int c;
bool TurnedUp = false;
bool TurnedDown = false;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 7 additional buffers are used for counting.
   IndicatorBuffers(7);   
   
//---- drawing settings
   
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);
   
   
   
   SetIndexBuffer(4,sum);        
   SetIndexBuffer(5,wt);         
   SetIndexBuffer(6,lsma_ma);
   
//---- initialization done
   return(0);
  }

int start()

{
   Draw4HowLong = Bars-Rperiod - 5;                            //Rperiod = 20
   length = Rperiod;                                           //length now = 20  
   lsma_length = LSMA_Period;
   loopbegin = Draw4HowLong - length - 1;   
      
   for(shift = loopbegin; shift >= 0; shift--)  //  MAIN For Loop
   { 
      sum[1] = 0;                                              
      for(i = length; i >= 1  ; i--)             //LSMA loop
      {
         lengthvar = length + 1;                               //lengthvar = 21  
         lengthvar /= 3;                                       //lengthvar = 7
         tmp = 0;
         tmp = ( i - lengthvar)*Close[length-i+shift];         //tmp = 20 - 7 * close[20-i+shift]
         sum[1]+=tmp;
      }
      wt[shift] = sum[1]*6/(length*(length+1));  
      j = shift;
      lsma_ma[shift] = wt[j+1] + (wt[j]-wt[j+1])* 2/(lsma_length+1);
  
//========== COLOR CODING ===========================================                       
        
        
      ExtMapBuffer1[shift] = wt[shift]; 
      ExtMapBuffer2[shift] = lsma_ma[shift]; 
      ExtMapBuffer3[shift] = wt[shift]; 
      ExtMapBuffer4[shift] = lsma_ma[shift]; 
            
      if (wt[shift]  < lsma_ma[shift])
      {
          ExtMapBuffer4[shift] = EMPTY_VALUE;
          ExtMapBuffer3[shift] = EMPTY_VALUE;
      }          
        
   }
        
   if (Alerts)
   {
      if (wt[1] > lsma_ma[1])
      {
         if (!TurnedUp)
         {
            Alert ("Triggerlines turned up on ",Symbol(),"-",Period());
            PlaySound("alert.wav");
            TurnedUp = true;
            TurnedDown = false;
         }
      }
      if (wt[1] < lsma_ma[1])
      {
         if (!TurnedDown)
         {
            Alert ("Triggerlines turned down on ",Symbol(),"-",Period());
            PlaySound("timeout.wav");
            TurnedDown = true;
            TurnedUp = false;
         }
      }
   }
}
//+------------------------------------------------------------------+

Comments