TriggerLines5c_AlertEmailSounds

Download script
TriggerLines5c_AlertEmailSounds

The Trigger Line is a technical analysis tool designed to help traders identify momentum shifts and potential trend reversals by comparing two distinct types of moving averages. Instead of simply looking at price history, this script calculates specific weighted values to highlight when the market's "speed" changes direction.

Core Logic and Visual Behavior

The indicator works by calculating a primary signal line and a secondary smoothed average. The relationship between these two lines determines what is displayed on your chart:

  • Weighted Momentum Calculation: The script calculates a specific weighted value based on price history. This reflects the immediate "weight" or momentum of the current price action.
  • Smoothed Trend Line: It then applies a Linear Weighted Moving Average (LSMA) to that momentum data. This serves as a baseline to smooth out minor market noise, providing a clearer picture of the underlying trend.
  • Dynamic Color Coding: To make the chart easier to read at a glance, the indicator changes its visual behavior based on the crossover of these two lines:
    • When the primary momentum is lower than the smoothed average, the script highlights the data in one color (Maroon).
    • When the primary momentum breaks above the smoothed average, it switches to a different set of colors (Yellow and DodgerBlue) to signal an upward shift.

Alerts and Notifications

Beyond visual cues on the chart, the script is equipped with a notification system to ensure you don't miss key transitions. It monitors the "cross" between the momentum and the smoothed average:

  1. Trend Up: When the momentum line crosses above the smoothed average, the script can trigger an alert.
  2. Trend Down: When the momentum line drops below the smoothed average, it triggers a secondary alert.

Users can configure these notifications to appear as on-screen pop-up boxes, be sent via email, or play specific sound files (such as a "signal" or "timeout" sound) to provide multi-sensory confirmation of a trend change. This logic ensures that you are notified only at the moment the "Trigger Line" flips, preventing repetitive alerts during a sustained trend.

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

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 5            
#property indicator_color1 Maroon       
#property indicator_color2 Blue     
#property indicator_color3 Yellow
#property indicator_color4 Red
#property indicator_color5 DodgerBlue

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1

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

int width;

extern int Rperiod = 15;
extern int LSMA_Period = 5;

extern bool Alerts         = false;
extern bool    AlertBox    = true;
extern bool    AlertEmail  = false;
extern bool    playSoundfiles  = true;
extern string soundfileUpSig   = "alert.wav";
extern string soundfileDnSig   = "timeout.wav";

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(8);   
   
//---- drawing settings
   
   SetIndexBuffer(3,ExtMapBuffer1);
   SetIndexStyle(3,DRAW_LINE);
   
   SetIndexBuffer(0,ExtMapBuffer2);
   SetIndexStyle(0,DRAW_LINE);
   
   SetIndexBuffer(4,ExtMapBuffer3);
   SetIndexStyle(4,DRAW_LINE);
   
   SetIndexBuffer(1,ExtMapBuffer4);
   SetIndexStyle(1,DRAW_LINE);
   
   SetIndexBuffer(2,ExtMapBuffer0);
   SetIndexStyle(2,DRAW_LINE);
   
   
   SetIndexBuffer(5,sum);        
   SetIndexBuffer(6,wt);         
   SetIndexBuffer(7,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 ===========================================                       
        
      ExtMapBuffer0[shift] = wt[shift]; 
      ExtMapBuffer2[shift] = lsma_ma[shift]; 

      ExtMapBuffer1[shift] = EMPTY_VALUE;
      ExtMapBuffer3[shift] = EMPTY_VALUE;
      ExtMapBuffer4[shift] = EMPTY_VALUE;

      if (wt[shift]  < lsma_ma[shift])    
      ExtMapBuffer1[shift] = wt[shift]; 
                                          
      if (wt[shift]  > lsma_ma[shift])    {
      ExtMapBuffer3[shift] = wt[shift]; 
      ExtMapBuffer4[shift] = lsma_ma[shift];
                                          }
            
        
   }
        
   if (Alerts)
   {
      if (wt[1] > lsma_ma[1])
      {
         if (!TurnedUp)
         {
            if (AlertBox)  Alert   ("Triggerlines turned up on ",Symbol(),"-",Period());
            if (AlertEmail)SendMail("Triggerlines turned up on ",Symbol()+" M"+Period()+" at"+Bid );
            if (playSoundfiles) PlaySound(soundfileUpSig);
            TurnedUp = true;
            TurnedDown = false;
         }
      }
      if (wt[1] < lsma_ma[1])
      {
         if (!TurnedDown)
         {
            if (AlertBox)  Alert   ("Triggerlines turned down on ",Symbol(),"-",Period());
            if (AlertEmail)SendMail("Triggerlines turned down on ",Symbol()+" M"+Period()+" at"+Bid );
            if (playSoundfiles) PlaySound(soundfileDnSig);
            TurnedDown = true;
            TurnedUp = false;
         }
      }
   }
}
//+------------------------------------------------------------------+

Comments