VininI_HMA_Sound&Alert_en

Download script
Author: MT4 release WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104
VininI_HMA_Sound&Alert_en

This script is a specialized technical analysis tool designed to help traders identify market trends by smoothing out price fluctuations and highlighting the direction of momentum. It utilizes a sophisticated mathematical approach called the Hull Moving Average (HMA) logic, which is specifically engineered to reduce "lag"—the delay often found in standard moving averages—while maintaining a smooth visual profile.

Core Logic and Functionality

1. Trend Smoothing and Calculation The script works by processing price data through several layers of calculation:

  • It first creates a weighted value based on the relationship between two different average periods.
  • It then calculates a "square root" average of those values to further refine the curve.
  • This multi-step process results in a trend line that reacts quickly to new price movements but remains steady enough to filter out insignificant market "noise."

2. Visual Trend Identification To make the data easy to read at a glance, the script categorizes the movement into three distinct visual components:

  • The Signal Line: This is the primary moving average line that shows the overall smoothed path of the price.
  • Uptrend Detection (Green): The script identifies upward momentum by comparing the current value of the signal line to its previous position. If the value is increasing, it highlights the "Up" trend.
  • Downtrend Detection (Red): Conversely, if the value is decreasing compared to the previous point, it identifies a "Down" trend.

3. Real-Time Notifications The script is designed to act as an active monitoring tool rather than just a static drawing on a chart. It includes a built-in alert system that watches for specific "trend flips." When the logic detects that the market has switched from an upward movement to a downward one (or vice versa), it triggers:

  • Auditory Alerts: A sound notification plays immediately upon a trend change.
  • Visual Pop-ups: An on-screen alert message notifies the user of the specific direction of the change (e.g., "HMATrendChange, UP").

Summary for the User

In simple terms, this tool acts as a "trend filter." It cleans up the messy movements of the market to show you the clear path of price action. By identifying exactly when the trend shifts from bullish to bearish, it allows traders to stay aligned with the prevailing market direction while providing instant notifications so they don't have to watch the screen constantly.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alertsIt issuies visual alerts to the screen
13 Views
0 Downloads
0 Favorites
VininI_HMA_Sound&Alert_en
//+------------------------------------------------------------------+ 
//| HMA.mq4 
//| Copyright © 2006 WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104 
//| wizardserg@mail.ru 
//| Revised by IgorAD,igorad2003@yahoo.co.uk | 
//| Personalized by iGoR AKA FXiGoR for the Trend Slope Trading method (T_S_T)
//| Link: 
//| contact: thefuturemaster@hotmail.com 
//+------------------------------------------------------------------+
#property copyright "MT4 release WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104" 
#property link "wizardserg@mail.ru" 

// "Modify 2008, Victor Nicolev"
// link "vinin.ucoz.ru"
// Óáðàë âñå ÿâíûå îøèáêè, òåïåðü èíäèêòîð ìîæíî èñïîëüçîâàòü â ñîâåòíèêå
// Ïðè èñïîëüçîâàíèè â îñâåòíèêå îáðàùàòüñÿ ê íóëåâîìó áóôôåðó
// Óáðàíà ïåðåðèñîâêà

#property indicator_chart_window 
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green 
#property indicator_color3 Red 
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

//---- input parameters 
extern int period=16; 
extern int method=3; // MODE_SMA 
extern int price=0; // PRICE_CLOSE 
extern int sdvig=0;

extern bool bPlaySound=true;           // Âêëþ÷åíèå çâóêà ïðè ñìåíå öâåòà
extern bool bAllert=true;           // Âêëþ÷åíèå çâóêà ïðè ñìåíå öâåòà
extern string SoundName="alert.wav";   // Çâóêîâîé ôàéë
extern int CheckBar=1;  
//---- buffers 


double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];

double vect[]; 
double alertTag,alert1Tag;
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function | 
//+------------------------------------------------------------------+ 
int init() { 
   IndicatorBuffers(4); 
   SetIndexBuffer(0, ExtMapBuffer); 
   SetIndexBuffer(1, Uptrend); 
   SetIndexBuffer(2, Dntrend); 
   SetIndexBuffer(3, vect); 
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);

   SetIndexDrawBegin(0,1*period);
   SetIndexDrawBegin(1,2*period);
   SetIndexDrawBegin(2,3*period);

   IndicatorShortName("Signal Line("+period+")"); 
   SetIndexLabel(1,"UP");
   SetIndexLabel(2,"DN");
   return(0); 
} 

//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function | 
//+------------------------------------------------------------------+ 
int deinit() { return(0); } 

//+------------------------------------------------------------------+ 
//| ?????????? ??????? | 
//+------------------------------------------------------------------+ 
double WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method, price, x+sdvig)); } 

//+------------------------------------------------------------------+ 
//| Custom indicator iteration function | 
//+------------------------------------------------------------------+ 
int start() { 
   int counted_bars = IndicatorCounted(); 

   if (counted_bars < 0) return(-1); 
   if (counted_bars > 0) counted_bars--;
   
   int p = MathSqrt(period); 

   int i, limit0,limit1,limit2;
   
   limit2=Bars - counted_bars;
   limit1=limit2;
   limit0=limit1;

   if (counted_bars==0){
      limit1-=(period);
      limit2-=(2*period);
   }

   for(i = limit0; i >= 0; i--)    vect[i]          = 2*WMA(i, period/2) - WMA(i, period); 
   for(i = limit1; i >= 0; i--)    ExtMapBuffer[i]  = iMAOnArray(vect, 0, p, 0, method, i); 
   for(i = limit2; i >= 0; i--) { 
      Uptrend[i] = EMPTY_VALUE; if (ExtMapBuffer[i]> ExtMapBuffer[i+1]) Uptrend[i] = ExtMapBuffer[i]; 
      Dntrend[i] = EMPTY_VALUE; if (ExtMapBuffer[i]< ExtMapBuffer[i+1]) Dntrend[i] = ExtMapBuffer[i]; 
   }
   if (bPlaySound && alertTag!=Time[0]) {
      if ((Uptrend[CheckBar+1]==EMPTY_VALUE && Uptrend[CheckBar]!=EMPTY_VALUE  ) 
         || (Dntrend[CheckBar+1]==EMPTY_VALUE && Dntrend[CheckBar]!=EMPTY_VALUE)) PlaySound(SoundName);
             alertTag=Time[0];
   }
   if (bAllert && alert1Tag!=Time[0]) {
      string mes="";
      if (Uptrend[CheckBar+1]==EMPTY_VALUE && Uptrend[CheckBar]!=EMPTY_VALUE)  mes="HMATrendChange, UP";
      if (Dntrend[CheckBar+1]==EMPTY_VALUE && Dntrend[CheckBar]!=EMPTY_VALUE)  mes="HMATrendChange, DN";
      if (mes!="") Alert(mes);   alert1Tag=Time[0];
   }

   return(0); 
} 
//+------------------------------------------------------------------+

Comments