VininI_HMA_sound&Alert
Download scriptThis script functions as a visual trend analysis tool designed to help traders identify the direction and momentum of price movements on a trading chart. Rather than simply following the raw price, it uses a smoothed mathematical approach to filter out "noise" and highlight the underlying trend.
Core Logic and Functionality
1. Trend Smoothing and Calculation The script works by calculating a specific type of moving average. It creates a primary signal line by performing a series of mathematical operations on price data over a user-defined period. This results in a smoothed line that represents the "flow" of the market. Because it uses these calculations, it reacts more fluidly to market shifts than standard moving averages might.
2. Directional Identification The script analyzes the slope of this signal line to determine market behavior:
- Upward Momentum: When the current value of the signal line is higher than the previous value, the script identifies an upward trend.
- Downward Momentum: When the current value is lower than the previous value, it identifies a downward trend.
3. Visual Feedback The tool provides clear visual cues on the chart to distinguish between these movements:
- It maps specific colors (Yellow, Green, and Red) to different trend conditions, allowing a trader to see at a glance whether the current momentum is rising or falling.
- It specifically highlights "Up" and "Down" segments, making it easier to spot transitions between bullish and bearish phases.
4. Automated Alerts Beyond just visual representation, the script includes an intelligent notification system:
- Trend Change Detection: It monitors for "inflection points"—moments where the direction of the slope changes (e.g., moving from a peak to a valley or vice versa).
- Audio and Pop-up Notifications: When a significant trend reversal is detected, the script can trigger a sound alert and a pop-up notification on the trading platform.
- Dynamic Messaging: The alerts are programmed to distinguish between "rising" and "falling" trends, providing the user with immediate context regarding the new market direction.
Summary for the User
In simple terms, this script acts as a "trend compass." It filters out minor price fluctuations to show you the main path the market is taking. It paints that path on your screen and sends you an alert the moment that path takes a significant turn, helping you stay aligned with the prevailing market direction.
//+------------------------------------------------------------------+
//| 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[];
//+------------------------------------------------------------------+
//| 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();
static bool bs=false, ba=false;
int bTime=0;
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 (bTime<Time[0]) {
bs=false;
ba=false;
}
if ((ExtMapBuffer[CheckBar+2]-ExtMapBuffer[CheckBar+1])*(ExtMapBuffer[CheckBar+1]-ExtMapBuffer[CheckBar])<0){
bTime=Time[0];
if (bPlaySound && !bs) {
PlaySound(SoundName);
bs=true;
}
if (bAllert && !ba) {
string mes="";
if (ExtMapBuffer[CheckBar]-ExtMapBuffer[CheckBar+1]>0) mes="Ñìåíà òðåíäà, âîñõîäÿùèé";
if (ExtMapBuffer[CheckBar]-ExtMapBuffer[CheckBar+1]<0) mes="Ñìåíà òðåíäà, íèñõîäÿùèé";
if (mes!="") Alert(mes);
ba=true;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments