Supertrend Audible Alert

Download script
Author: Copyright � 2005, Jason Robinson (jnrtrading).
Supertrend Audible Alert

The Supertrend script is a visual trading tool designed to help identify and follow the prevailing direction of a market's price movement. It simplifies complex market data into a clear, color-coded trend line that assists traders in deciding whether the current momentum is moving upward or downward.

Core Logic and Behavior

Trend Identification The script works by analyzing two primary components of market movement: momentum and volatility. It monitors price fluctuations to determine if the market is experiencing a sustained push in one direction. When the trend shifts, the indicator visually switches its position and color on your chart to reflect the change.

Dynamic Price Buffers Unlike a static moving average, this script uses "Average True Range" (ATR) calculations. This means it accounts for how much the price is actually swinging over a set period. By incorporating this volatility data, the tool creates a "buffer" or "boundary" around the price:

  • In an Upward Trend: It calculates a support level based on recent price lows and volatility. The line stays flat or moves upward as long as the price remains healthy; if the price drops significantly toward this line, it indicates a potential trend exhaustion.
  • In a Downward Trend: It calculates a resistance level based on recent price highs and volatility. The line remains at its peak or moves downward, acting as a ceiling that tracks the market's decline.

Momentum Filtering To ensure the trend changes are significant and not just "noise" from minor price ticks, the script utilizes a momentum indicator (CCI). This acts as a filter: the trend only flips when the momentum values cross a specific threshold. This prevents the indicator from flickering back and forth during choppy, sideways market conditions.

Visual and Audio Notifications The tool is designed for real-time monitoring. It provides clear visual cues by changing colors (typically Lime for upward movements and Red for downward movements). Additionally, it features an automated alert system that triggers a sound notification the moment the momentum crosses the threshold, instantly notifying the trader of a trend reversal without requiring them to watch the screen constantly.

Indicators Used
Commodity channel indexIndicator of the average true range
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
Supertrend Audible Alert
//+------------------------------------------------------------------+
//|                                                   Supertrend.mq4 |
//|                   Copyright © 2005, Jason Robinson (jnrtrading). |
//|                                      http://www.jnrtrading.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)."
#property link      "http://www.jnrtrading.co.uk"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red


double TrendUp[];
double TrendDown[];
int st = 0;
//extern int SlowerEMA = 6;

extern bool Enable_AudibleAlert = true;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexBuffer(0, TrendUp);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexBuffer(1, TrendDown);
   
   /*SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 159);
   SetIndexBuffer(0, TrendUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 159);
   SetIndexBuffer(1, TrendDown);*/
   
   /*for(int i = 0; i < Bars; i++) {
      TrendUp[i] = NULL;
      TrendDown[i] = NULL;
   }*/
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   /*for(int i = 0; i < Bars; i++) {
      TrendUp[i] = NULL;
      TrendDown[i] = NULL;
   }*/
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| This fucntion will make audible alert when condition has met                      |
//+------------------------------------------------------------------+
void AudibleAlert(bool condition)
{
   int iCurrent = 0;
   static int iLast = 0;
   static bool first_time = true;
     
   
   if(condition==true)  
      iCurrent = 1; 
   else
      iCurrent = 2; 
   
   if(first_time == true) 
   {
      iLast = iCurrent; //is it first run?
      first_time = false;
   }
   
   if(iCurrent != iLast) 
   {
      string sDirection="";
      if(iCurrent==1) sDirection = "TrendUp";
      if(iCurrent==2) sDirection = "TrendDown";
      string sMsg = "Supertrend on ("+ Symbol() + ") has changed (" + sDirection + ")!";
      Alert(sMsg);
      iLast = iCurrent;
   }
   
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   
   int limit, i, counter;
   double Range, AvgRange, cciTrendNow, cciTrendPrevious, var;

   int counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) counted_bars--;
   

   limit=Bars-counted_bars;
   
     
   for(i = limit; i >= 0; i--) {
      cciTrendNow = iCCI(NULL, 0, 50, PRICE_TYPICAL, i);
      cciTrendPrevious = iCCI(NULL, 0, 50, PRICE_TYPICAL, i+1);
      
      //st = st * 100;
      
      
      counter = i;
      Range = 0;
      AvgRange = 0;
      for (counter = i; counter >= i-9; counter--) {
         AvgRange = AvgRange + MathAbs(High[counter]-Low[counter]);
      }
      Range = AvgRange/10;
      if (cciTrendNow >= st && cciTrendPrevious < st) {
         TrendUp[i+1] = TrendDown[i+1];
      }
      
      if (cciTrendNow <= st && cciTrendPrevious > st) {
         TrendDown[i+1] = TrendUp[i+1];
      }
      
      if (cciTrendNow >= st) {
         TrendUp[i] = Low[i] - iATR(NULL, 0, 5, i);         
         if (TrendUp[i] < TrendUp[i+1]) {
            TrendUp[i] = TrendUp[i+1];
         }
      }
      else if (cciTrendNow <= st) {
         TrendDown[i] = High[i] + iATR(NULL, 0, 5, i);
         if (TrendDown[i] > TrendDown[i+1]) {
            TrendDown[i] = TrendDown[i+1];
         }
      }
   }
   
   
   //---- code added by coders guru 
   //---- Alerts on color changing
   if(Enable_AudibleAlert)
   AudibleAlert(cciTrendNow >= st);
        
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments