Hull Moving Average Indicator in MQL5 - Trend Change marked by a Buffer/ Output

MQL5 Indicators

Job finished

Execution time 44 minutes
Feedback from customer
Simple. Good Work.
Feedback from employee
Thanks so much!!!!!

Specification

Dear coders,

we need a Hull Moving Average Indicator (HMA) in MQL5.

The following buffers with certain outputs are needed:

  • A trend change - marked by the HMA - needs to be detectable by an output/ buffer of the required indicator.

    For instance a switch from a positive slope to a negative slope of the HMA is marked with a "-1" as output.

    A switch from a negative slope to a positive slope of the HMA is marked with a "+1" as output.

  • An uptrend - marked by the HMA - is marked with "+1"

  • A downtrend - marked by the HMA - is marked with "-1"


An alternative would be:

  • For instance a switch from a positive slope to a negative slope of the HMA is marked by buffer 1.

    A switch from a negative slope to a positive slope of the HMA is marked by buffer 2.

  • An uptrend - marked by the HMA - is marked by buffer 3.

  • A downtrend - marked by the HMA - is marked by buffer 4.

Introduction to the idea behind the HMA

The Hull Moving Average (HMA) attempts to minimize the lag of a traditional moving average while retaining the smoothness of the moving average line. The HMA can be interpreted in a similar way to traditional moving averages, but it responds more quickly. Like other moving averages, it can be used to confirm a trend or spot a change in the trend.


Calculation of the HMA

The formula for the Hull Moving Average uses two different weighted moving averages (WMAs) of price, plus a third WMA to smooth the raw moving average. There are three parts to the calculation. In the formulas listed below, “n” indicates the number of periods specified by the chartist.


First, calculate two WMAs: one with the specified number of periods and one with half the specified number of periods.

WMA1 = WMA(n/2) of price

WMA2 = WMA(n) of price


Second, calculate the raw (non-smoothed) Hull Moving Average.

Raw HMA = (2 * WMA1) - WMA2


Third, smooth the raw HMA with another WMA, this one with the square root of the specified number of periods.

HMA = WMA(sqrt(n)) of Raw HMA


Of course, when you divide a whole number by two or calculate its square root, you don't always end up with a whole number as a result. In that case, we round the result to the nearest whole number, so we can use that as the number of periods when calculating weighted moving averages.

For example, when calculating an 11-day HMA, we end up with non-whole numbers for two of our WMAs. For calculating the n/2 WMA, 11/2 is 5.5, so we would round that up to 6 for the WMA calculation. For the sqrt(n) WMA, the square root of 11 is 3.317, so we would round that down to 3 for the number of WMA periods in the final smoothing calculation.

You can find an exemplary HMA in MQL4 down below (CAUTIOUS: This MQL4 version does not have a buffer, which marks a trend change. BUT we need that in the MQL5 version). However, there you see how the HMA is calculated:

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters 
extern int       period=15;
extern int       method=3;                        
extern int       price=0;                           
//---- buffers 
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init()
  {
   IndicatorBuffers(3);
   SetIndexBuffer(0, Uptrend);
   //ArraySetAsSeries(Uptrend, true); 
   SetIndexBuffer(1, Dntrend);
   //ArraySetAsSeries(Dntrend, true); 
   SetIndexBuffer(2, ExtMapBuffer);
   ArraySetAsSeries(ExtMapBuffer, true);
//----
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
//----
   IndicatorShortName("Signal Line("+period+")");
   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));
  }
//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)
      return(-1);
//----
   int x=0;
   int p=MathSqrt(period);
   int e=Bars - counted_bars + period + 1;
//----
   double vect[], trend[];
//----
   if(e > Bars)
      e=Bars;
//----
   ArrayResize(vect, e);
   ArraySetAsSeries(vect, true);
   ArrayResize(trend, e);
   ArraySetAsSeries(trend, true);
//----
   for(x=0; x < e; x++)
     {
      vect[x]=2*WMA(x, period/2) - WMA(x, period);
      }
   for(x=0; x < e-period; x++)
//----
      ExtMapBuffer[x]=iMAOnArray(vect, 0, p, 0, method, x);
   for(x=e-period; x>=0; x--)
     {
      trend[x]=trend[x+1];
      if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
      if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
      if (trend[x]>0)
        { 
         Uptrend[x]=ExtMapBuffer[x];
         if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
         Dntrend[x]=EMPTY_VALUE;
        }
      else
         if (trend[x]<0)
           {
            Dntrend[x]=ExtMapBuffer[x];
            if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
            Uptrend[x]=EMPTY_VALUE;
           }
      }
   return(0);
  }
//+------------------------------------------------------------------+ 


This screenshot shows the HMA with a inputPeriod of 50. The aimed indicator should look like this at the end and mark those switches from green to red/ red to green.

Please let me know if anything remains unclear!





Responded

1
Developer 1
Rating
(2422)
Projects
3042
66%
Arbitration
77
48% / 14%
Overdue
340
11%
Working
2
Developer 2
Rating
(298)
Projects
427
26%
Arbitration
18
61% / 33%
Overdue
26
6%
Free
3
Developer 3
Rating
(119)
Projects
169
38%
Arbitration
9
78% / 22%
Overdue
15
9%
Free
4
Developer 4
Rating
(167)
Projects
192
11%
Arbitration
37
38% / 35%
Overdue
5
3%
Loaded
Similar orders
preciso de um robô com duas médias móveis, uma exponencial high e uma exponencial low. preciso também ter a opção de utilizar e todos os tempos gráficos e alterar os parâmetros das médias. entrada de compra será feita quando um candle de alta romper e fechar a cima da média high e fechará a posição quando um candle de baixa romper e fechar a baixo da média low. a venda será feita quando o candle de baixa romper e
Greetings, As the title suggests, I am trying to convert an indicator that calls itself via an iCustom call like this. iMAArray_Buffer[loop_1] = iCustom ( NULL , Selected_TF, MQLInfoString ( MQL_PROGRAM_NAME ), "calculate" , RPeriod, MType, MPeriod, 1 , shift); Full code will not be provided, only the position that needs fixing. I cannot get this working in MQL5 but the original code runs smoothly in MQL4. Please
I need a chart to replicate/track my equity + Balance Curve into my mt4. Also this chart i need to be able to add Stochastic / Bollingerband / Moving average on the equity/balance curve. Besides the equity curve i would like the indicator to show the Line-chart of my win + 1 and my loss -1 which results in a win-loss curve. ( i will discuss this with the choosen developer in depth. ) More information on what i want
Greetings great developer, I am in search of a highly skilled developer to assist with an exciting project. I need to convert two open-source TradingView indicators to NinjaTrader 8 and implement a usage restriction based on computer IDs. If you have experience with NinjaTrader 8 coding please let me know. I’d be happy to discuss the details further
Hello, This is pretty simple and its an indicator with On/Off button 1-Off will remove all indicator from the chart. 2-On will put them all back again with the same settings
Trading bot 300+ USD
We need bot that trades when medium and low impact news hits It will release pending order both directions few min prior to news impact And will have certain risk management strategy attached Example If Monday and Tuesday news successful clears profits It will reduce risk for next news events until new week starts each week message on tg: Dstatewealthtrading NOTE: 4 YAERS OF EXPERIENCE UPWORD, YOU MUST BE A
I need someone the create a supertrend indicator based on Heikin Ashi candles instead of normal candles. Needs to be exactly the same as the supertrend (original one) + ha from tradingview. In m1,m5,m15 the indicator must have the same values ​​found with the tradingview. Work that meets this requirement will be accepted ( depending on the broker and spread, however, a few pips of difference will be accepted)
Here is a detailed instruction for the coder to implement the vertical lines based on the BrainTrainSignalAlert indicator: --- **Task: Implement Vertical Lines for Alerts from BrainTrainSignalAlert Indicator** **Objective:** Create a system that adds vertical lines on specified timeframes (M5 or M30) whenever an alert is generated by the BrainTrainSignalAlert indicator on the H1, H4, and D1 timeframes. The lines
Hello Guys! I want to modify/fix the indicator that uses sequential type of entries (it calculates from 1 to 9) and if the conditions are met it provides an arrow (signal) with alert. The problem is that, sometimes (for unknown for me reasons) it repaints arrow signal. Like on the picture: Signal 1 - correct signal Signal 2 - correct signal Signal 3 - correct signal Signal 4 - repaints (signal 3 arrow dissapeared
Hi, I have a Live Data feature for my trading accounts that lets me check details like total open positions, number of lots, profits, etc. I need someone to add the number of pending orders to this live data. This is important for me to ensure that all accounts have the same number of pending orders, since I use a copy trading system. Also, there is a website where I check all the data. In this case, you would need

Project information

Budget
30 - 50 USD
VAT (19%): 5.7 - 9.5 USD
Total: 35.7 - 59.5 USD
For the developer
27 - 45 USD
Deadline
from 1 to 5 day(s)