TriggerLines_AlertEmailSounds
Download scriptThe "Trigger Line" indicator is designed to help traders identify trend momentum and potential entry points by visualizing the relationship between two specific moving averages on a separate window within the trading platform. Its primary goal is to smooth out market "noise" and provide a clear visual signal of when price momentum shifts from upward to downward, or vice versa.
Core Logic and Mechanism
The indicator functions by calculating two distinct types of data:
-
The Weighted Calculation: Unlike simple moving averages that treat all past prices equally, this script uses a weighted approach. It assigns different levels of importance to price data over a specific period (defined by the
Rperiodsetting). This allows the indicator to be more responsive to recent price changes while still maintaining a stable overall view of the trend. -
The Linear Smoothing (LSMA): The script takes that weighted data and applies a secondary layer of smoothing, similar to a Linear Weighted Moving Average (LSMA). This second calculation helps neutralize erratic spikes in the market, creating a "cleaner" line that follows the primary trend more fluidly.
Visual Representation
The indicator plots these two calculations as lines on your chart:
- Trend Dynamics: By comparing the primary weighted value against the smoothed average, the indicator creates a dynamic relationship.
- Color Coding: The script is programmed to change the visual output based on the position of these lines relative to one another. When the values align in a specific direction (indicating a dominant trend), the lines are highlighted. If they cross or fall below a certain threshold, the script can suppress certain lines (setting them to "Empty"), effectively clearing the screen of data that no longer represents the current momentum.
Automated Alerts
To ensure traders do not have to watch the charts constantly, the logic includes a notification system based on "crossover" events:
- Bullish Signal: If the primary weighted value moves above the smoothed average, the system recognizes an upward trend shift.
- Bearish Signal: If the primary weighted value drops below the smoothed average, it recognizes a downward trend shift.
When these shifts occur, the script can be configured to trigger multiple types of notifications simultaneously:
- On-Screen Alerts: A pop-up message box appearing on the platform.
- Email Notifications: Sending an instant alert to your registered email address with the current price.
- Audio Cues: Playing specific sound files (like "alert.wav" or "timeout.wav") to provide an immediate audible signal of the trend change.
In summary, this script acts as a sophisticated trend-tracking tool that filters out market volatility, highlights the direction of price movement through visual color coding, and provides proactive alerts whenever the market momentum flips.
//+------------------------------------------------------------------+
//| 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
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
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(7);
//---- drawing settings
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexStyle(3,DRAW_LINE);
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)
{
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