Skip to main content

How to Build a Hull Moving Average (HMA) in Profectus.AI

Learn how to build a Hull Moving Average (HMA) in Profectus.AI using Formula blocks and Variables. Calculate HMA values, compare candle ID 1 and 2, detect bullish or bearish direction, and use the result in your trading bot logic.

Summary

The Hull Moving Average (HMA) is a trend-following indicator designed to react faster than a normal moving average while staying smooth. In Profectus.AI, you do not always need a built-in indicator block for every indicator. Many indicators are just formulas, and formulas can be recreated with Formula blocks and Variables.

This article shows the logic behind building an HMA-style indicator inside Profectus.AI and using it as part of your trading bot.


The Core Idea

An indicator is usually just math.

If you know the calculation behind an indicator, you can often rebuild it inside Profectus.AI by using:

  • Inputs for adjustable settings, such as the HMA period

  • Variables to store calculated values

  • Formula blocks to calculate the indicator step by step

  • Trade Rule blocks to use the final value in your strategy

For the Hull Moving Average, the goal is simple:

  1. Calculate the HMA value of the last closed candle

  2. Calculate the HMA value of the candle before that

  3. Compare both values

  4. Decide if the HMA is moving up or down


What the HMA Tells You

In the example from the video:

  • If the latest HMA value is higher than the previous HMA value → the HMA is rising

  • If the latest HMA value is lower than the previous HMA value → the HMA is falling

This can be translated into a simple trend signal:

  • HMA rising = bullish / green

  • HMA falling = bearish / red

You can then use this signal in your trading logic.


Example Setup

Let’s say you want to use the HMA as a simple trend filter.

Create these variables:

Variable

Purpose

HMA_Candle_1

Stores the HMA value of the last closed candle

HMA_Candle_2

Stores the HMA value of the candle before that

HMA_Green

Stores whether the HMA is rising or not

You can also create an input:

Input

Purpose

HMA_Period

Lets you adjust the HMA period in MetaTrader 5


Step 1 — Calculate the HMA Value of Candle ID 1

Start with a Run per Candle block.

Then add a Formula block that calculates the HMA value for Candle ID 1, which is the last fully closed candle.

Store the result in:

HMA_Candle_1

This value represents the current confirmed HMA value.


Step 2 — Calculate the HMA Value of Candle ID 2

Add a second Formula block.

This one calculates the same HMA formula, but for Candle ID 2, which is the candle before the last closed candle.

Store the result in:

HMA_Candle_2

Now your bot has two HMA values it can compare.


Step 3 — Compare Both HMA Values

Add a Trade Rule block:

HMA_Candle_1 > HMA_Candle_2

If this is true, the HMA is rising.

Then use a Modify Variables block to set:

HMA_Green = 1

If the condition is false, set:

HMA_Green = 0

This turns the HMA direction into a simple value your bot can use.


Step 4 — Use the HMA in a Strategy

Once HMA_Green exists, you can use it like any other condition.

Example:

  1. Add Run per Candle

  2. Add Trade Rule

  3. Check if:

HMA_Green = 1

  1. If true, trigger a Buy Now block

This means:

Every new candle, if the HMA is rising, the bot is allowed to buy.

This is only a simple example. In a real strategy, you would usually combine this with additional filters, risk settings, and trade management.


Why This Matters

The HMA example teaches a bigger lesson:

You are not limited to the indicators already visible in the platform.

If an indicator can be broken down into a formula, you can often recreate it with:

  • Formula blocks

  • Variables

  • Inputs

  • Trade Rules

That means you can build custom indicators, modify them, test different settings, and use the output directly inside your strategy logic.


Make It Your Own

You can experiment with:

  • Changing the HMA period

  • Running it on another timeframe

  • Using it as a trend filter instead of a direct entry

  • Combining it with price action patterns

  • Allowing buys only when HMA is rising

  • Allowing sells only when HMA is falling

Export the bot after each change and test it in MetaTrader 5 Visual Mode to confirm the logic behaves as expected.


Conclusion

The Hull Moving Average is a good example of how custom indicators can be rebuilt inside Profectus.AI. Instead of waiting for every indicator to exist as a prebuilt block, you can recreate indicator logic yourself using Formula blocks and Variables.

If you can understand the formula, you can turn it into blocks.

Did this answer your question?