Bác thử mấy cái này xem sao, e k dùng stochastic để trade nên k thử. Chúc may mắn!
/*Positive Stochastic Divergence for use in
Indicator Builder and Automatic Analysis (scan mode),
by Dimitris Tsokakis*/
ST33=STOCHD(14);
TR1=LLVBARS(ST33,4);
TR2=IIF(ST33<30 AND TR1>0 AND REF(TR1,-1)==0,ref(ST33,-1),0);
TRC=IIF(TR2>0,C,0);
vs=valuewhen(tr2, ref(st33,-1), 1);
dvs=vs-ref(vs,-1);
vc=valuewhen(trc, LLV(c,3), 1);
dvc=vc-ref(vc,-1);
diver=iif(dvs>0 and dvc<0,30,0);
DAS=BARSSINCE(REF(TR2,-1)>0);
DD=IIF(DAS<20 AND C>=REF(C,-1),DIVER,0);
GRAPH0=TR2;
GRAPH0STYLE=2;
graph0barcolor=12;
graph1=dd;
graph1barcolor=5;
BUY=DD>0 ;
/*Negative Stochastic divergence for use in
Indicator Builder and Automatic Analysis (scan mode),
by Dimitris Tsokakis*/
ST33=stochd(14);
TR1=HHVBARS(ST33,4);
TR2=IIF(ST33>70 AND TR1>0 AND REF(TR1,-1)==0,ref(ST33,-1),0);
TRC=IIF(TR2>0,C,0);
vs=valuewhen(tr2, ref(st33,-1), 1);
dvs=vs-ref(vs,-1);
vc=valuewhen(trc, HHV(H,3), 1);
dvc=vc-ref(vc,-1);
diver=iif(dvs<0 and dvc>0,90,0);
DAS=BARSSINCE(REF(TR2,-1)>0);
ddd=IIF(DAS<20 AND C<REF(C,-1),DIVER,0);
GRAPH1=TR2;
graph0=ddd;
graph0barcolor=4;
GRAPH1STYLE=2;
graph1barcolor=1;
SELL=ddd==90;
_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 );
myStochD =StochD( periods , Ksmooth, DSmooth );
myStochK =StochK( periods , Ksmooth);
Overbought = 80 ;
Oversold =20 ;
Center = 50 ;
Buy1 = Cross(myStochK, Oversold ) ;
Buy2 = Cross(myStochK, Center ) ;
Sell1 = Cross( Overbought, myStochK );
Sell2 = Cross( Center, myStochK );
Plot( myStochD, "Stochastic %D"+_PARAM_VALUES( ), ParamColor( "ColorD", colorRed ), ParamStyle(" StyleD") );
Plot( myStochK, "Stochastic %K", ParamColor( "ColorK", colorBlue ), ParamStyle(" StyleK") );
PlotShapes(IIf( Sell1, shapeDownArrow , shapeNone), colorRed,0, Offset=Null) ;
PlotShapes(IIf( Sell2, shapeDownArrow , shapeNone), colorRed,0, Offset=Null) ;
PlotShapes(IIf( Buy1 , shapeUpArrow , shapeNone), colorGold,0, Offset=Null) ;
PlotShapes(IIf( Buy2 , shapeUpArrow , shapeNone), colorGold,0, Offset=Null) ;
Plot(Overbought, "",colorRed) ;
Plot(Oversold, "",colorGreen) ;
Plot(Center, "",colorWhite, styleDashed) ;
y0=LastValue( Trough(StochD( periods , Ksmooth, DSmooth ),1,2));
y1=LastValue( Trough(StochD( periods , Ksmooth, DSmooth ),1,1));
x0=BarCount - 1 - LastValue(TroughBars(StochD( periods , Ksmooth, DSmooth ),1,2));
price_start= Close[x0] ;
x1=BarCount - 1 - LastValue(TroughBars(StochD( periods , Ksmooth, DSmooth ),1,1));
price_end=Close[ x1];
Line = LineArray( x0, y0, x1, y1, 0 );
Plot( Line, "Support line", colorYellow );
Buy = y1>y0 AND price_end<price_start;
PlotShapes(shapeUpArrow * Buy, colorGreen,0, Line);
y00=LastValue( Peak(StochD( periods , Ksmooth, DSmooth ),1,2));
y11=LastValue( Peak(StochD( periods , Ksmooth, DSmooth ),1,1));
x00=BarCount - 1 - LastValue(PeakBars( StochD(periods , Ksmooth, DSmooth ),1,2));
price_start1= Close[x00] ;
x11=BarCount - 1 - LastValue(PeakBars( StochD(periods , Ksmooth, DSmooth ),1,1));
price_end1=Close[ x11];
Line = LineArray( x00, y00, x11, y11, 0 );
Plot( Line, "Resistance line", colorBrightGreen );
Sell = y11<y00 AND price_end1>price_start1;
PlotShapes(shapeDownArrow * Sell, colorOrange,0,Line) ;
PlotOHLC( myStochK,myStochK, 50,myStochK, "", colorDarkGrey, styleCloud | styleClipMinMax, Oversold , Overbought);
PlotOHLC( myStochD,myStochD, 50,myStochD, "", colorDarkRed, styleCloud | styleClipMinMax, Oversold , Overbought);
//Optimize
range = Optimize( "Range", 8, 8, 14, 1 );
Ksmooth = Optimize("%K smooth", 3, 2, 5, 1 );
Dsmooth = Optimize("%D smooth", 3, 2, 5, 1 );
Buy=Cross( StochK (range,Ksmooth) , StochD (range,Ksmooth, Dsmooth) );
Sell = Cross( StochD(range, Ksmooth,Dsmooth) , StochK(range, Ksmooth) );
_SECTION_END( );
/*Positive Stochastic Divergence for use in
Indicator Builder and Automatic Analysis (scan mode)*/
ST33=StochD(14);
TR1=LLVBars(ST33,4);
TR2=IIf(ST33<30 AND TR1>0 AND Ref(TR1,-1)==0,Ref(ST33,-1),0);
TRC=IIf(TR2>0,C,0);
vs=ValueWhen(tr2, Ref(st33,-1), 1);
dvs=vs-Ref(vs,-1);
vc=ValueWhen(trc, LLV(C,3), 1);
dvc=vc-Ref(vc,-1);
diver=IIf(dvs>0 AND dvc<0,30,0);
DAS=BarsSince(Ref(TR2,-1)>0);
DD=IIf(DAS<20 AND C>=Ref(C,-1),DIVER,0);
Graph0=TR2;
Graph0Style=2;
Graph0BarColor=12;
Graph1=dd;
Graph1BarColor=5;
Buy=DD>0 ;