Help with the Stochastic %D formula

#1
Hi,

Please could you help me with the below formula.

I don't know anything about coding. I tried to do some experiment. I tried to add buy sell signals to formula of Stochastic %D. But I am not getting the results.

The condition is
Buy when %D crosses Oversold line from below
Sell when %D crosses Overbought line from above

_SECTION_BEGIN("Stochastic %D");
periods = Param( "Periods", 15, 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") );

Overbought= 80; Oversold= 20;
Plot(Overbought,"OB",colorRed);
Plot(Oversold,"OS",colorGreen);

Buy = Cross(DSmooth, Oversold ) ;
Sell = Cross( Overbought, DSmooth );

PlotShapes( shapeSmallUpTriangle * Buy + shapeSmallDownTriangle * Sell, IIf( Buy, colorGold, colorRed ) );

_SECTION_END();

Thanks.
 
#2
pnaphade

try this

_SECTION_BEGIN("Stochastic %D");
periods = Param( "Periods", 15, 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") );
Overbought= 80; Oversold= 20;
Plot(Overbought,"OB",colorRed);
Plot(Oversold,"OS",colorGreen);
Buy = Cross(StochD(periods,Ksmooth,Dsmooth), Oversold ) ;
Sell = Cross( Overbought, StochD(periods,Ksmooth,Dsmooth ));
PlotShapes( shapeSmallUpTriangle * Buy + shapeSmallDownTriangle * Sell, IIf( Buy, colorGold, colorRed ) );
_SECTION_END();

vidyasagar
 

Similar threads