Jurik Moving Average AFL for AmiBroker

Krishnendu Bhattacharyya

New Member
Below is my code for Jurik Moving Average. It's an error free interpretation of tradingview pine script into AmiBroker AFL. Though error free and plotting a line, but still it is not functional. How can it be fixed? Please help.

Code:
``````_SECTION_BEGIN( "Jurik Moving Average" );
SetBarsRequired( 100, 0 );

function jmapow( src, len )
{
upperband = src;
lowerband = src;

del1 = src - Ref( upperband, -1 );
del2 = src - Ref( lowerband, -1 );
volty = IIf( abs( del1 ) == abs( del2 ), 0, Max( abs( del1 ), abs( del2 ) ) );

vSum = 0.0;

for( i = 10; i < BarCount; i++ )
{
vSum += Nz( vSum[i] ) + 0.1 * ( volty[i] - Nz( volty[i - 10], volty[i] ) );
}

avgLen = 65;
avgVolty = MA( vSum, avgLen );

alen = ( len - 1 ) / 2;
len1 = Max( log( sqrt( alen ) ) / log( 2 ) + 2, 0 );
pow1 = Max( len1 - 2, 0.5 );

rVolty = IIf( avgVolty != 0, volty / avgVolty, 0 );
rVolty += IIf( rVolty > len1 ^ ( 1 / pow1 ), len1 ^ ( 1 / pow1 ), IIf( rVolty < 1, 1, rVolty ) );

pow2  = rVolty ^ pow1;

return pow2;
}

function jurikma( src, len, pow, ph )
{
phr = IIf( ph < -100, 0.5, IIf( ph > 100, 2.0, ( ph / 100 ) + 1.5 ) );
beta = 0.54 * ( len - 1 ) / ( 0.45 * ( len - 1 ) + 2 );
pow = jmapow( src, len );
alpha = beta ^ pow;

e0 = 0.0;
e1 = 0.0;
e2 = 0.0;
jma = 0.0;

for( i = 0; i < BarCount; i++ )
{
e0[i] += ( 1 - alpha[i] ) * src[i] + alpha[i] * Nz( e0[i] );
e1[i] += ( src[i] - e0[i] ) * ( 1 - beta[i] ) + beta[i] * Nz( e1[i] );
e2[i] += ( e0[i] + ( phr[i] * e1[i] ) - Nz( jma[i] ) ) * ( ( 1 - alpha[i] ) ^ 2 ) + ( alpha[i] ^ 2 ) * Nz( e2[i] );
jma[i] += e2[i] + Nz( jma[i] );
}

return jma;
}

src = ( High + Low + Close ) / 3;
len = Param( "Length", 14, 5, 100, 1 );
pow = Param( "Power", 2, 1, 100, 1 );
ph = Param( "Phase", 0, -100, 100, 1 );

Plot( jurikma( src, len, pow, ph ), "Jurik Moving Average", colorBrown, styleNoLabel | styleNoRescale | styleThick );
_SECTION_END();``````