HMA_Cross
Download scriptThis script is a specialized trading indicator designed to identify potential market trends by analyzing the interaction between two different moving averages. Specifically, it utilizes the Hull Moving Average (HMA), which is known for its ability to balance smoothness with rapid responsiveness to price changes.
Core Logic and Functionality
The primary objective of this tool is to detect "crossovers"—moments where one moving average line passes through another. The logic operates as follows:
1. Dual Indicator Tracking The script monitors two distinct Hull Moving Averages simultaneously. Each has its own specific settings, such as its period (the length of time it looks back at data) and price type. By comparing a "fast" moving average against a "slow" moving average, the tool helps distinguish between short-term price fluctuations and broader market momentum.
2. Signal Identification
- Buy Signals: The script looks for a specific transition where the first moving average moves from below the second to above it. When this upward crossover occurs, the script identifies a potential bullish sentiment.
- Sell Signals: Conversely, it monitors for instances where the first moving average moves from above the second to below it, signaling a potential bearish shift in the market.
3. Visual and Audible Alerts To ensure traders do not have to watch the charts constantly, the script includes several notification features:
- On-Chart Markers: It automatically places visual arrows on the chart at the exact moment a crossover is confirmed, clearly highlighting "Up" or "Down" signals.
- Audible Notifications: The tool can be configured to play a specific sound file when a signal occurs.
- Pop-up Alerts: It can trigger a text alert window providing the symbol and time of the crossover.
- Live Comments: For users who prefer a real-time data feed, the script can display a live comment on the chart screen showing current prices (Ask and Bid) alongside the timestamp of the signal.
Summary for the User
In simple terms, this script acts as an automated lookout. It watches two price lines; every time they cross each other, it flags the move as a potential trend change and notifies you immediately via sounds, text, or visual icons on your screen. This allows you to react more quickly to market shifts without needing to manually interpret complex line movements.
//+------------------------------------------------------------------+
//| HMA Cross.mq4 |
//| Revamped and Formatted For HMA By BLUR71 |
//| Original Code By Kalenzo, Modded By Newdigital |
//+------------------------------------------------------------------+
#property copyright "BLUR71"
#property link "blrobertsjr@hotmail.com"
#property link "www.forex-tsd.com"
#property indicator_chart_window
#property indicator_color1 Aqua
#property indicator_color2 Magenta
#property indicator_width1 3
#property indicator_width2 3
#property indicator_buffers 2
extern string HMAFile = "HMA Color NRP";
extern double HMAPeriod1 = 7,
HMAPrice1 = 6,
HMAType1 = 3,
HMAPeriod2 = 12,
HMAPrice2 = 6,
HMAType2 = 3,
SellFilter = 0,
BuyFilter = 0;
extern string AlertFile = "Alert.wav";
extern bool AlertCross = true,
AlertSound = false,
AlertInfo = false,
DataSelect = false;
//----
double UpBuffer[],
DnBuffer[],
alertBar;
//----
int init()
{SetIndexStyle(0,DRAW_ARROW,EMPTY);
SetIndexStyle(1,DRAW_ARROW,EMPTY);
SetIndexBuffer(0,UpBuffer);
SetIndexBuffer(1,DnBuffer);
SetIndexArrow(0,233);
SetIndexArrow(1,234);
SetIndexLabel(0,"Up");
SetIndexLabel(1,"Down");
if(DataSelect==false)
SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
return(0);}
//----
int deinit()
{ return(0); }
//----
int start()
{int limit,
counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i = 0 ;i < limit ;i++)
{double PrevHMA1 = iCustom(NULL,0,HMAFile,HMAPeriod1,HMAPrice1,HMAType1,0,i+1),
CurrHMA1 = iCustom(NULL,0,HMAFile,HMAPeriod1,HMAPrice1,HMAType1,0,i),
PrevHMA2 = iCustom(NULL,0,HMAFile,HMAPeriod2,HMAPrice2,HMAType2,0,i+1),
CurrHMA2 = iCustom(NULL,0,HMAFile,HMAPeriod2,HMAPrice2,HMAType2,0,i);
//----
if( CurrHMA1 > (CurrHMA2 +(BuyFilter*Point)) && PrevHMA1 <= PrevHMA2)
{UpBuffer[i] = iLow(Symbol(),0,i)-(3*Point);
DnBuffer[i] = EMPTY_VALUE;
if (AlertSound==1) PlaySound(AlertFile);
if (AlertCross==1 && Bars>alertBar) {Alert(Symbol(),Period()," HMA "+DoubleToStr(HMAPeriod1,0)+" x "+
DoubleToStr(HMAPeriod2,0)+" Buy");alertBar = Bars;}
if (AlertInfo==1) Comment (" HMA X Buy @ Ask:",Ask,", Bid:",Bid,", ",TimeToStr(CurTime(),TIME_DATE)," ",
TimeHour(CurTime()),":",TimeMinute(CurTime()),", ",Symbol()," ",Period());}
else if( PrevHMA1 >= PrevHMA2 && CurrHMA1 < (CurrHMA2 - (SellFilter*Point)))
{UpBuffer[i] = EMPTY_VALUE;
DnBuffer[i] = iHigh(Symbol(),0,i)+(3*Point);
if (AlertSound==1) PlaySound(AlertFile);
if (AlertCross==1 && Bars>alertBar) {Alert(Symbol(),Period()," HMA "+DoubleToStr(HMAPeriod1,0)+" x "+
DoubleToStr(HMAPeriod2,0)+" Sell");alertBar = Bars;}
if (AlertInfo==1) Comment (" HMA X Sell @ Ask:",Ask,", Bid:",Bid,", ",TimeToStr(CurTime(),TIME_DATE)," ",
TimeHour(CurTime()),":",TimeMinute(CurTime()),", ",Symbol()," ",Period());}
else
{DnBuffer[i] = EMPTY_VALUE;
UpBuffer[i] = EMPTY_VALUE;}}
//----
return(0);}
//----
Comments