**Re: Hull Moving Average**
PHP:

```
_SECTION_BEGIN("Hull Moving Average");
Period = Param("Period",79,1,500,1);
Hull = WMA( 2*WMA(C,int(Period/2))- WMA(C,Period),int(sqrt(Period)));
for( i = 1 ; i < BarCount-2; i++ )
{
if (hull[i] <hull[i-1] && hull[i] <hull[i+1])
Lpml[i]=1;
else
Lpml[i] =0;
if (hull[i] >hull[i-1] && hull[i] >hull[i+1])
Lpmh[i]=1;
else
Lpmh[i] =0;
}
GR =ExRem(LpmH,Lpmh);
RD =ExRem(Lpml,Lpml);
PlotShapes(IIf(GR!=0,shapeSmallCircle,shapeNone),colorRed,0,hull,0);
PlotShapes(IIf(RD!=0,shapeSmallCircle,shapeNone),colorBrightGreen,0,hull,0);
Plot(Hull,"Hull "+Period+" days",2,1);
_SECTION_END();
```

Hi Yasu,

This is good code.

Here we have a 79 period Hull average and we are looking for the turning points.

Also, you can achieve the same result without loop, using array which will be faster.

But as with every indicator, the signal is valid only after the close of current candle.

Also, HMA is a inbuilt function in Amibroker.

What do you think, simpler

_SECTION_BEGIN("Hull Moving Average");

Period = Param("Period",79,1,500,1);

Hull = HMA(Close, Period);

lpmh = Ref(hull,-1) > Ref(hull,-2) AND Ref(hull,-1) > hull;

lpml = Ref(hull,-1) < Ref(hull,-2) AND Ref(hull,-1) < hull;

GR =ExRem(LpmH,Lpmh);

RD =ExRem(Lpml,Lpml);

PlotShapes(IIf(GR!=0,shapeSmallCircle,shapeNone),colorRed,0,hull,0);

PlotShapes(IIf(RD!=0,shapeSmallCircle,shapeNone),colorBrightGreen,0,hull,0);

Plot(Hull,"Hull "+Period+" days",2,1);

_SECTION_END();

From amibroker help :

SYNTAX HMA( array, range )

RETURNS ARRAY

FUNCTION Implements Hull Moving Average. It is functionally equivalent to the following code:

function HMA_AFL( array, period )

{

fast = WMA( array, period / 2 );

slow = WMA( array, period );

return WMA( 2 * fast - slow, sqrt( period ) );

}