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

MQL5 インディケータ

仕事が完了した

実行時間44 分
依頼者からのフィードバック
Simple. Good Work.
開発者からのフィードバック
Thanks so much!!!!!

指定

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!





応答済み

1
開発者 1
評価
(2672)
プロジェクト
3408
68%
仲裁
77
48% / 14%
期限切れ
342
10%
パブリッシュした人: 1 code
2
開発者 2
評価
(298)
プロジェクト
427
26%
仲裁
18
61% / 33%
期限切れ
26
6%
パブリッシュした人: 8 codes
3
開発者 3
評価
(119)
プロジェクト
169
38%
仲裁
9
78% / 22%
期限切れ
15
9%
4
開発者 4
評価
(174)
プロジェクト
200
12%
仲裁
39
38% / 33%
期限切れ
5
3%
パブリッシュした人: 2 codes
類似した注文
Version document : 1.0 Plateforme : TradingView Langage : Pine Script v6 Type : Indicateur d'analyse et d'aide à la décision (non-exécutant) 1. Présentation du projet Nom du produit ONYX SR V2 — Intelligent Support & Resistance Scalping System Objectif Créer un indicateur TradingView capable d'identifier automatiquement des opportunités de scalping basées sur : supports et résistances dynamiques ; action du prix ;
I have a EA/indicator that I want built. I should say 1st off dont know how to code myself so I will be using AI to verify that the source code is complete and matches the documents spec or if better so if you can not truly do the job do not waste either of out time. This is a idea I came.up wit and used AI to produce a framework for it.... and of course AI isn't 100% accurate so I need a knowledgeable quantitative
TumiiFX 30 - 20000 USD
1. Use two EMAs: 20 and 50. If EMA 20 is above EMA 50 → uptrend (look for buys) If EMA 20 is below EMA 50 → downtrend (look for sells) 2. Wait for a pullback into the area between the two EMAs. - For buys: price must touch or move between EMA 20 and EMA 50 during the last few candles. - For stils: same idea, but in a downtrend. 3. Entry signal: Buy: a bullish engulfing candle in an uptrend after the pullback
I am looking for an experienced MQL4 developer to build a professional High-Frequency Trading (HFT) / Low-Latency Expert Advisor for MetaTrader 4 (MT4) . The EA will be deployed on an IC Markets Live account and should be optimized for the fastest possible execution using a low-latency VPS located in LD4 or NY4 . The primary instruments will be US30 and XAUUSD (Gold) . The goal is to create an EA capable of
A robot 50+ USD
HIGH-FREQUENCY M5/M15 CONCURRENT ENTRY SNIPER import time class HighFrequencySniper: def __init__(self): self.target_profit = 25.00 # Targeted Delta Move self.max_execution_time = 3600 # 1 Hour Sandbox (Seconds) self.lot_allocation = "CALIBRATED_TO_RISK" def execute_hft_scan(self, current_price, m5_rsi, m15_order_block): print(f"[SCANNING] Current Kernel Metric: ${current_price:.2f
I need a trading bot, please i need this project urgently and when messaing me kindly send me samples of past works and dont forget i need the project to be done as soon as possible
A lightweight MT5 chart overlay displaying total floating P&L, average entry price, combined lot size, and current symbol exposure as a percentage of account balance, all updating in real time with color-coded profit/loss indicators, delivered with clean object-oriented source code and no DLL dependencies
QUIERO CONSEGUIR EL CODIGO FUENTE DE ESTE INDICADOR QUE ME GUSTA MUCHO TAMBIEN TIENE EL NOMBRE DE ET BANDS O ENTRY EXIT TIMING . no se los componentes pero estas son las imagenes. que mejor lo describen
I am looking to convert my existing TradingView Pine Script (v5) strategy into an MQL5 Expert Advisor (EA) for MetaTrader 5. Strategy Details: Asset: Gold (XAUUSD) Timeframe: 15-minute Strategy Logic: The strategy is based on a breakout concept. Anchor Candle: The base calculation starts from the Specified Candle Entry Window: The EA should only look for entries As Per Indicator Risk Management: The strategy
I want to find a Developer to perform this work and settle payments in this Application. I undertake not to communicate with Applicants anywhere else except this Application, including third-party messengers, personal correspondence or emails. I understand that violators will be banned from publishing Orders in the Freelance

プロジェクト情報

予算
30 - 50 USD
締め切り
最低 1 最高 5 日