TriggerLines_SigAlertEmailSounds_sw

Download script
TriggerLines_SigAlertEmailSounds_sw

This script is a technical analysis tool designed to help traders identify momentum shifts and potential entry or exit points by analyzing price trends. It functions by calculating two primary mathematical lines that react differently to market volatility and price movement.

Core Logic and Visualization

The indicator works by processing historical price data to create two distinct components:

  1. The Weighted Trend Line: The script calculates a weighted average of the closing prices. Unlike a standard moving average where all recent prices might carry equal importance, this logic applies a specific multiplier to different parts of the look-back period. This helps the line stay more responsive to significant price changes while smoothing out minor "noise."
  2. The Linear Smoothed Moving Average (LSMA): The script then generates a secondary, smoother line based on the first weighted line. Think of this as a "trend of a trend"—it acts as a baseline to determine whether the current momentum is accelerating or decelerating.

On your chart, these two lines interact to show the relationship between immediate price action and the broader trend. When the primary weighted line moves above or below this smoother baseline, it indicates a change in market sentiment.

Signal Detection and Alerts

The tool is programmed to recognize specific "crossover" events where these two lines intersect:

  • Trend Shifts: The script monitors every new price tick to see if the weighted line has crossed the smoothed baseline.
  • Visual Cues: Depending on your settings, the indicator can display arrows at the exact moment these crossovers occur. This serves as a visual confirmation that the momentum has shifted from bullish (upward) to bearish (downward), or vice versa.
  • Dynamic Distance: To ensure signals aren't too cluttered, the script can place these visual markers at a specific distance from the lines, calculated based on current market volatility (ATR). This ensures that the arrows remain readable even during high-activity periods.

Notification System

Beyond just providing visual data on the chart, the script includes an automated notification engine. If enabled, it monitors the crossover logic in real-time and can trigger three types of alerts simultaneously:

  • On-Screen Popups: A text alert appears directly on your trading platform.
  • Email Notifications: Sends a summary to your linked email address containing the symbol, timeframe, and current price at the moment of the crossover.
  • Audio Alerts: Plays a specific sound file to notify you immediately if you are away from your screen.

By combining smoothed trend analysis with real-time alerts, this script aims to filter out minor price fluctuations and highlight significant shifts in market direction for more informed decision-making.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1It sends emailsIt plays sound alerts
11 Views
0 Downloads
0 Favorites
TriggerLines_SigAlertEmailSounds_sw
//+------------------------------------------------------------------+
//|                                                     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_separate_window
#property  indicator_buffers 4            
#property indicator_color1 Blue     
#property indicator_color2 Red
#property indicator_color3 DodgerBlue 
#property indicator_color4 Tomato

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1

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

int width;

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

extern int LineSigMode = 1;
extern double arrowDist =0.55;

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";
extern string LineSignalMode   = "lines-0, lines&sig-1, sig-2";


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;
double arrplot,arrplot1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 7 additional buffers are used for counting.
   IndicatorBuffers(7);   
   
//---- drawing settings
   
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   
   if (LineSigMode!=2){   SetIndexStyle(0,DRAW_LINE);   SetIndexStyle(1,DRAW_LINE); }
   else               {   SetIndexStyle(0,DRAW_NONE);   SetIndexStyle(1,DRAW_NONE); }
   
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
 
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   
   if (LineSigMode>0){    
   SetIndexStyle(2,DRAW_ARROW);  SetIndexArrow(2,233); SetIndexEmptyValue(2,EMPTY_VALUE);
   SetIndexStyle(3,DRAW_ARROW);  SetIndexArrow(3,234); SetIndexEmptyValue(3,EMPTY_VALUE);
                     }
   
   
   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 (LineSigMode>0) 
      {
         ExtMapBuffer3[shift]= EMPTY_VALUE;
         ExtMapBuffer4[shift]= EMPTY_VALUE;    
         
         if (wt[shift]<lsma_ma[shift] && wt[shift+1]>=lsma_ma[shift+1])
         ExtMapBuffer4[shift] = lsma_ma[shift]+arrowDist*iATR(NULL,0,7,shift);

         if (wt[shift]>lsma_ma[shift] && wt[shift+1]<=lsma_ma[shift+1])
         ExtMapBuffer3[shift] =  lsma_ma[shift]-arrowDist*iATR(NULL,0,7,shift);
      }
        
   }      
   
   if (Alerts)
   {
      if (wt[1] > lsma_ma[1])
      {
         if (!TurnedUp)
         {
            if (AlertBox)  Alert   ("Triggerlines turned up on ",Symbol()," M",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()," M",Period());
            if (AlertEmail)SendMail("Triggerlines turned down on ",Symbol()+" M"+Period()+" at"+Bid );
            if (playSoundfiles) PlaySound(soundfileDnSig);
            TurnedDown = true;
            TurnedUp = false;
         }
      }
   }
}
//+------------------------------------------------------------------+

Comments