# Using ALMA cross in AFL programming

I have a problem with using ALMA. I want to buy when ALMA cross MA and sell when MA cross ALMA. I tried to code myself, there is no error but the formula doesn't work. Please help. Thank you.

function ALMA_AFL( input, range, offset, sigma )
{
local m, im, s, Coeff;

m = floor( Offset * (range - 1) );
s = range / sigma;

for( i = 0; i < Min( range, BarCount ); i++ )
{
im = i - m; // apply shift
Coeff[ i ] = exp( - ( im * im )/ ( 2 * s * s ) ); // Gaussian distribution
}

return FIR( input, Coeff, range );
}

P = ParamField("Price field",-1);
Periods = Param("Periods", 7, 2, 300, 1, 10 );
Offset = Param("Offset", 0.85, 0, 1, 0.01 );
sigma = Param("Sigma", 6, 1, 10, 0.1 );
Plot( ALMA_AFL( P, Periods, Offset, Sigma ), _DEFAULT_NAME(), ParamColor( "Color", colorBlue ), ParamStyle("Style", styleThick,maskDefault) );

_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

Plot(MA(C,100), "ma100", colorGreen, styleLine,0,0,0,0,1);
Buy = Cross(ALMA_AFL( P, Periods, Offset, Sigma ), MA(C,100));
PlotShapes(Buy*shapeCircle, colorBlack, 0, 0, -12, 0);

First and foremost there there are two initial problems with your post:

1. You have not read here. It is mandatory rule to use code tags if inserting code
2. 90% of "your" code is copy and paste from other sources. So you should rather add reference to actual original coder if posting code not being yours.

Now, as for your "issue"... you do not get shown shapes because you did set zero to y-position's function argument of PlotShapes function (see 4th argument of that function).

Next... you should avoid to call a function over and over again but if it is used multiple times you should rather store to a variable (making code faster and better maintainable).

So by taking all of upper things in mind we get:

``````function ALMA_AFL( input, range, offset, sigma )
{
/// code from FIR function reference and AB forum:
local m, im, s, Coeff;

m = floor( Offset * ( range - 1 ) );
s = range / sigma;

for( i = 0; i < Min( range, BarCount ); i++ )
{
im = i - m; // apply shift
Coeff[ i ] = exp( - ( im * im ) / ( 2 * s * s ) ); // Gaussian distribution
}

return FIR( input, Coeff, range );
}

P = ParamField("Price field",-1);
Periods = Param("Periods", 7, 2, 300, 1, 10 );
Offset = Param("Offset", 0.85, 0, 1, 0.01 );
sigma = Param("Sigma", 6, 1, 10, 0.1 );
my_alma = ALMA_AFL( P, Periods, Offset, Sigma );
Plot( my_alma, _DEFAULT_NAME(), ParamColor( "Color", colorBlue ), ParamStyle("Style", styleThick,maskDefault) );

_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

my_ma = MA(C,100);