AFL is not giving BUY and SELL signal

This AFL is not giving any BUY/SELL Signal.Please help me in generating BUY/SELL signal.

_SECTION_BEGIN("MACD");

diff = MACD(12, 26) - Signal(12,26,9);

myBuy = (diff < 0) & (diff > Ref(diff,-1));
mySell = (diff > 0) & (diff < Ref(diff,-1));

Buy1=ExRem( myBuy, mySell );
Sell1=ExRem( mySell, myBuy );
_SECTION_END();

_SECTION_BEGIN("Stochastic");

periods = Param( "Periods", 14, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

_SECTION_BEGIN("Stochastic %K");
periods = Param( "Periods", 14, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Plot( StochK( periods , Ksmooth), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

periods = Param( "Periods", 14, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

_SECTION_BEGIN("Stochastic %K");
periods = Param( "Periods", 14, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Plot( StochK( periods , Ksmooth), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Stochastic %K1");
periods = Param( "Periods", 14, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Plot( StochK( periods , Ksmooth), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

Plot(80,"", colorBlue, styleThick |styleNoLabel);
Plot(20,"", colorBlue, styleThick |styleNoLabel);

Buy2=Cross(StochD(14,3,3),20);
Sell2=Cross(80,StochD(14,3,3));
_SECTION_END();

_SECTION_BEGIN("SMI");

_SECTION_BEGIN("SMI - Stochastic Momentum Index");
SetChartBkColor( colorBlack ) ;
LookBack = Optimize("LookBack",Param("Lookback", 25, 1, 100 ),1,30,1);
Smooth1 = Optimize("Smooth 1",Param("Smooth 1", 5, 1, 100 ),1,30,1);
Smooth2 = Param("Smooth 2", 5, 1, 20 );
Trigger = Param("Signal", 25, 1, 25);
PP = ParamField("Price field",-1);
SMILevel = Param("Level", 40, 10, 40, 10);

HH = HHV( H, LookBack );
LL = LLV( L, LookBack );

StoMom = 100 * EMA( EMA( PP - 0.5 * ( HH + LL ), Smooth1 ), Smooth2 ) /
( 0.5 * EMA( EMA( HH - LL, Smooth1 ), Smooth2 ) );
StoSig = MA(StoMom,3);

Plot (StoMom,_DEFAULT_NAME(),IIf(StoMom> Ref(StoMom,-1),colorBrightGreen,colorBrightGreen), styleLine+styleNoLabel);
Plot (StoSig,"",colorRed,styleLine+styleNoLabel);
Plot(0,"",31,styleNoLabel);
Plot( SMILevel,"",colorOrange,styleDashed);
Plot(-SMILevel,"",colorOrange,styleDashed);

Buy3=Cross(StoMom,StoSig);
Sell3=Cross(StoSig,StoMom);
_SECTION_END();

Buy = (Buy1 AND Buy2 AND Buy3);
Sell = (Sell1 AND Sell2 AND Sell3);
BuyPrice = Close;
SellPrice = Close;

//AlertIf( Buy , "SOUND C:\Windows\Media\Ding.wav", "Audio alert", 2 );

This AFL is not giving any BUY/SELL Signal.Please help me in generating BUY/SELL signal.

@drana, could it be that you never get all three buy conditions true at the same time? My guess is that your "CROSS" signals happen "too quickly" and don't line up on the same day as your BUY code requires.

Also, when posting code, please use the code tags (",/.") to help format your code and make it easier for us to test with.

Anyway, back to the code.... Now that you have the code, can you do an Exploration so you can see where the various buy conditions are happening? Then you can decide how you would like to modify your criteria to get the BUY and SELL signals when you want. The Exploration is one of the many tools to help you debug your own code. Give it a try, and post it (within a Code Block) so we can see how it is going.

1 Like