Stochastics Divergence.......A little help needed.

#1
Below is the screenshot of the Stocastic Indicator with Divergence and Crossover Buy Sell Indicator..........The indicator shows buy/sell arrow whenever the stochastics make crossover irrespective of where the cossover occurred........I want a little help from the coders..........The indicator should show buy/sell arrows for the crossovers that occur in OverBought and OverSold (20 and 80) levels...........Can some one please add the code for the.








_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( );
 

amitrandive

Well-Known Member
#2
Below is the screenshot of the Stocastic Indicator with Divergence and Crossover Buy Sell Indicator..........The indicator shows buy/sell arrow whenever the stochastics make crossover irrespective of where the cossover occurred........I want a little help from the coders..........The indicator should show buy/sell arrows for the crossovers that occur in OverBought and OverSold (20 and 80) levels...........Can some one please add the code for the.



Check if this is what you want.

Code:
_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( );
 
#3
Check if this is what you want.

Code:
_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( );
Thanks for the help man............its very helpful.........Can u do the same for this code aswell.........It will be of great help for me.........I've tried but no crossover signal occurs when code is modified as the way u did.


_SECTION_BEGIN("Unnamed 172");
/* DT Oscillator
**
** AFL translation by X-Trader
** X-Trader.net
**
*/
SetChartBkColor(ParamColor("Outer Panel",colorBlack));

PeriodRSI= Param("PeriodRSI", 33, 1, 250, 1);
PeriodStoch=Param("PeriodStoch", 21, 1, 250, 1);
MAType=Param("MAType", 2, 1, 2, 1);
PeriodSK=Param("PeriodSK", 18, 1, 250, 1);
PeriodSD=Param("PeriodSD", 4, 1, 250, 1);
Upper=Param("Upper", 75, 50, 100, 1);
Lower=Param("Lower", 25, 0, 50, 1);


StoRSI= 100*(( RSI( PeriodRSI) - LLV( RSI( PeriodRSI ) , PeriodStoch ) ) / ( ( HHV( RSI( PeriodRSI) , PeriodStoch ) ) - LLV(RSI( PeriodRSI ), PeriodStoch ) ) );

if(MAType==1)
{
SK=MA(StoRSI,PeriodSK);
SD=MA(SK,PeriodSD);
}

if(MAType==2)
{
SK=EMA(StoRSI,PeriodSK);
SD=EMA(SK,PeriodSD);
}

Plot(SK,"DTOscSK",ParamColor( "ColorSK", ParamColor( "Color", colorCycle ) ),ParamStyle ("Style"));
Plot(SD,"DTOscSD",ParamColor( "ColorSD", colorWhite ),styleDashed);
Plot(Upper,"Upper",ParamColor( "ColorUpper", colorRed ),styleLine);
Plot(Lower,"Lower",ParamColor( "ColorLower", colorGreen ),styleLine);

Buy= SD < SK;
Sell= SD > SK;
Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy);
PlotShapes( shapeHollowSmallCircle* Buy , colorGreen ,0);
PlotShapes( shapeHollowSmallCircle* Sell, colorRed ,0);

_SECTION_END();
 

amitrandive

Well-Known Member
#4
Thanks for the help man............its very helpful.........Can u do the same for this code aswell.........It will be of great help for me.........I've tried but no crossover signal occurs when code is modified as the way u did.
Try this

Code:
_SECTION_BEGIN("Unnamed 172");
/* DT Oscillator
**
** AFL translation by X-Trader
** X-Trader.net
**
*/
SetChartBkColor(ParamColor("Outer Panel",colorBlack));

PeriodRSI= Param("PeriodRSI", 33, 1, 250, 1);
PeriodStoch=Param("PeriodStoch", 21, 1, 250, 1);
MAType=Param("MAType", 2, 1, 2, 1);
PeriodSK=Param("PeriodSK", 18, 1, 250, 1);
PeriodSD=Param("PeriodSD", 4, 1, 250, 1);
Upper=Param("Upper", 75, 50, 100, 1);
Lower=Param("Lower", 25, 0, 50, 1);

StoRSI= 100*(( RSI( PeriodRSI) - LLV( RSI( PeriodRSI ) , PeriodStoch ) ) / ( ( HHV( RSI( PeriodRSI) , PeriodStoch ) ) - LLV(RSI( PeriodRSI ), PeriodStoch ) ) );

if(MAType==1)
{
SK=MA(StoRSI,PeriodSK);
SD=MA(SK,PeriodSD);
}

if(MAType==2)
{
SK=EMA(StoRSI,PeriodSK);
SD=EMA(SK,PeriodSD);
}

Plot(SK,"DTOscSK",ParamColor( "ColorSK", ParamColor( "Color", colorCycle ) ),ParamStyle ("Style"));
Plot(SD,"DTOscSD",ParamColor( "ColorSD", colorWhite ),styleThick);
Plot(Upper,"Upper",ParamColor( "ColorUpper", colorRed ),styleLine);
Plot(Lower,"Lower",ParamColor( "ColorLower", colorGreen ),styleLine);
Buy = Cross(SK, SD) AND SD<= 25;
Sell = Cross(SD, SK) AND SK >= 75;
PlotShapes(IIf( Sell, shapeDownArrow , shapeNone), colorRed,0, Offset=Null) ;
PlotShapes(IIf( Buy , shapeUpArrow , shapeNone), colorGreen,0, Offset=Null) ;

_SECTION_END();
 
#5
Try this

Code:
_SECTION_BEGIN("Unnamed 172");
/* DT Oscillator
**
** AFL translation by X-Trader
** X-Trader.net
**
*/
SetChartBkColor(ParamColor("Outer Panel",colorBlack));

PeriodRSI= Param("PeriodRSI", 33, 1, 250, 1);
PeriodStoch=Param("PeriodStoch", 21, 1, 250, 1);
MAType=Param("MAType", 2, 1, 2, 1);
PeriodSK=Param("PeriodSK", 18, 1, 250, 1);
PeriodSD=Param("PeriodSD", 4, 1, 250, 1);
Upper=Param("Upper", 75, 50, 100, 1);
Lower=Param("Lower", 25, 0, 50, 1);

StoRSI= 100*(( RSI( PeriodRSI) - LLV( RSI( PeriodRSI ) , PeriodStoch ) ) / ( ( HHV( RSI( PeriodRSI) , PeriodStoch ) ) - LLV(RSI( PeriodRSI ), PeriodStoch ) ) );

if(MAType==1)
{
SK=MA(StoRSI,PeriodSK);
SD=MA(SK,PeriodSD);
}

if(MAType==2)
{
SK=EMA(StoRSI,PeriodSK);
SD=EMA(SK,PeriodSD);
}

Plot(SK,"DTOscSK",ParamColor( "ColorSK", ParamColor( "Color", colorCycle ) ),ParamStyle ("Style"));
Plot(SD,"DTOscSD",ParamColor( "ColorSD", colorWhite ),styleThick);
Plot(Upper,"Upper",ParamColor( "ColorUpper", colorRed ),styleLine);
Plot(Lower,"Lower",ParamColor( "ColorLower", colorGreen ),styleLine);
Buy = Cross(SK, SD) AND SD<= 25;
Sell = Cross(SD, SK) AND SK >= 75;
PlotShapes(IIf( Sell, shapeDownArrow , shapeNone), colorRed,0, Offset=Null) ;
PlotShapes(IIf( Buy , shapeUpArrow , shapeNone), colorGreen,0, Offset=Null) ;

_SECTION_END();
Thanks for the help bro.........thanks a lot
 

Similar threads