Stochastic RSI and Slow stochastic

#2
Here the Stochastic RSI-MA for you::)

X=25;
Y=30;
z=25;
StocasticRSIMA=(Sum(RSI(X)-LLV(RSI(X),X),3)/Sum(HHV(RSI(X),X)-LLV(RSI(X),X),3))*100;
Media=MA((Sum(RSI(Y)-LLV(RSI(Y),Y),3)/Sum(HHV(RSI(Y),Y)-LLV(RSI(Y),Y),3))*100,Z);
Plot(20,"",colorGreen,styleLine);
Plot(80,"",colorRed,styleLine);
Plot(StocasticRSIMA,"StocasticRSIMA",colorRed,styleLine);
Plot(Media,"MA",colorRed,styleLine);
 

johnnypareek

Well-Known Member
#6
Dear all
i need these two afl.
hope to get your help.
thanks in advance.
Hi,

Got mail and tried to send you but you are not allowed to receive mails.

here it is

HTML:
Periods=Param("Periods",14,3,70,2);
SmoothFactor = Param("SM",3,3,14,1);
Levelup= 70;
Leveldown=30;
R= RSI(Periods);
StochR=100*(R-LLV(R,periods))/(HHV(R,periods)-LLV(R,periods));
SR=EMA(StochR,SmoothFactor);
Buy= Cross( SR,Leveldown);
Sell= Cross(Levelup,SR);
Short=Sell;
Cover=Buy;
Buy= ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
PH =30; 
RHeight = 100/PH*100;
GraphXSpace = 3*PH;
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
Plot(0,"",colorBlack,styleDashed|styleOwnScale,0,RHeight);
Plot(SR,"   RSI Value ",4,styleThick|styleOwnScale,0,RHeight);
Plot(Levelup,"     LevelUP ",colorPlum,styleDashed|styleOwnScale,0,RHeight);
Plot(Leveldown,"    Level Down",colorBlue,styleDashed|styleOwnScale,0,RHeight);
Plot(100,"",colorBlack,styleThick|styleOwnScale,0,RHeight);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
 

johnnypareek

Well-Known Member
#7
Dear all
i need these two afl.
hope to get your help.
thanks in advance.
Hmm try this I guess this is good then default slow stochd

HTML:
_SECTION_BEGIN("DoubleStochastic");
R = ((HHV(H,60) - C) /(HHV (H,60) -LLV (L,60))) *-100;
Period = 6;
EMA1 = EMA(R,Period);
EMA2 = EMA(EMA1,2);
se = EMA1 - EMA2;
ni = EMA1 + se;
PR = 0-abs(ni);
ra = MA(PR,2);
na = PR>=ra AND PR>=Ref(PR,-1) ;
tu = (PR < ra) OR PR>= ra AND PR< Ref(PR,-1) ;
barcolor = IIf( tu,colorRed, IIf( na, colorBrightGreen, 7));
Graph0 = PR;
Graph1 = ra;


pds = 10; /*Periods */
/*pds = Optimize("pds",13,2,20,1); */

slw = 13; /*Slowing for Full Stoch%K*/
/*slw = Optimize("slw",3,1,14,1); */



slwd = 5; /*Slowing for Full Stoch%D*/
/*slwd = Optimize("slwd",3,1,14,1); */
ob = 90; /*Overbought */
/*ob = Optimize("ob",83,65,88,1); */
os = 25; /*Oversold */
/*os = Optimize("os",24,20,50,1); */


FSK = 100*(C-LLV(L,pds))/(HHV(H,pds)-LLV(L,pds)); // FASTSTOCHK

FLSK = EMA( FSK, slw ); // FULLSTOCHK




DSK = ((FLSK-LLV(FLSK,pds))/(HHV(FLSK,pds)-LLV(FLSK,pds))) * 100;

DLSK = EMA( DSK, slwd ); // FULLSTOCHD



Buy = Cross (DSK ,DLSK);
Sell = Cross (DLSK ,DSK);
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGreen, colorRed ) ); 
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );

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






Plot( MA( DLSK, 4 ), "MA-3"+_PARAM_VALUES(),ParamColor("ColorD" , colorRed )); 

Plot( DLSK, "Stochastic %D"+_PARAM_VALUES(),ParamColor("ColorK" , colorBlue ), styleLine); 

Plot(Ob,"Overbought Level",colorRed, styleLine);
Plot(Os,"Oversold Level",colorGreen, styleLine); 

_SECTION_BEGIN("Candle Identification");
O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);
function CandlePattern(P)
   {
   global PatternName;
   if(P == 0) { PatternName = "NearDoji"; Pv = (abs(O-C)<= ((H-L)*0.1)); }
   else if(P == 1) { PatternName = "BlackCandle"; Pv = (O>C); }
   else if(P == 2) { PatternName = "LongBlackCandle"; Pv = (O>C AND
(O-C)/(.001+H-L)>.6); }
   else if(P == 3) { PatternName = "SmallBlackCandle"; Pv = ((O>C) AND
((H-L)>(3*(O-C)))); }
   else if(P == 4) { PatternName = "WhiteCandle"; Pv = (C>O); }
   else if(P == 5) { PatternName = "LongWhiteCandle"; Pv = ((C>O) AND
((C-O)/(.001+H-L)>.6)); }
   else if(P == 6) { PatternName = "SmallWhiteCandle"; Pv = ((C>O) AND
((H-L)>(3*(C-O)))); }
   else if(P == 7) { PatternName = "BlackMaubozu"; Pv = (O>C AND H==O AND
C==L); }
   else if(P == 8) { PatternName = "WhiteMaubozu"; Pv = (C>O AND H==C AND
O==L); }
   else if(P == 9) { PatternName = "BlackClosingMarubozu"; Pv = (O>C AND
C==L); }
   else if(P == 10) { PatternName = "WhiteClosingMarubozu"; Pv = (C>O AND
C==H); }
   else if(P == 11) { PatternName = "BlackOpeningMarubozu"; Pv = (O>C AND
O==H); }
   else if(P == 12) { PatternName = "WhiteOpeningMarubozu"; Pv = (C>O AND
O==L); }
   else if(P == 13) { PatternName = "HangingMan"; Pv = (((H-L)>4*(O-C)) AND
((C-L)/(.001+H-L)>= 0.75) AND ((O-L)/(.001+H-L)>= 0.75)); }
   else if(P == 14) { PatternName = "Hammer"; Pv = (((H-L)>3*(O-C)) AND
((C-L)/(.001+H-L)>0.6) AND ((O-L)/(.001+H-L)>0.6)); }
   else if(P == 15) { PatternName = "InvertedHammer"; Pv = (((H-L)>3*(O-C))
AND ((H-C)/(.001+H-L)>0.6) AND ((H-O)/(.001+H-L)>0.6)); }
   else if(P == 16) { PatternName = "ShootingStar"; Pv = (((H-L)>4*(O-C))
AND ((H-C)/(.001+H-L)>= 0.75) AND ((H-O)/(.001+H-L)>= 0.75)); }
   else if(P == 17) { PatternName = "BlackSpinningTop"; Pv = ((O>C) AND
((H-L)>(3*(O-C))) AND (((H-O)/(.001+H-L))<.4) AND
(((C-L)/(.001+H-L))<.4)); }
   else if(P == 18) { PatternName = "WhiteSpinningTop"; Pv = ((C>O) AND
((H-L)>(3*(C-O))) AND (((H-C)/(.001+H-L))<.4) AND
(((O-L)/(.001+H-L))<.4)); }
   else if(P == 19) { PatternName = "BearishAbandonedBaby"; Pv = ((C1 == O1)
AND (C2>O2) AND (O>C) AND (L1>H2) AND (L1>H)); }
   else if(P == 20) { PatternName = "BearishEveningDojiStar"; Pv = ((C2>O2)
AND ((C2-O2)/(.001+H2-L2)>.6) AND (C2<O1) AND (C1>O1) AND
((H1-L1)>(3*(C1-O1))) AND (O>C) AND (O<O1)); }
   else if(P == 21) { PatternName = "DarkCloudCover"; Pv = (C1>O1 AND
((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(.001+(H-L)>0.6)); }
   else if(P == 22) { PatternName = "BearishEngulfing"; Pv = ((C1>O1) AND
(O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1))); }
   else if(P == 23) { PatternName = "ThreeOutsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1>= C2) AND (O2>= C1) AND ((O1-C1)>(C2-O2)) AND (O>C) AND
(C<C1)); }
   else if(P == 24) { PatternName = "BullishAbandonedBaby"; Pv = ((C1 == O1)
AND (O2>C2) AND (C>O) AND (L2>H1) AND (L>H1)); }
   else if(P == 25) { PatternName = "BullishMorningDojiStar"; Pv = ((O2>C2)
AND ((O2-C2)/(.001+H2-L2)>.6) AND (C2>O1) AND (O1>C1) AND
((H1-L1)>(3*(C1-O1))) AND (C>O) AND (O>O1)); }
   else if(P == 26) { PatternName = "BullishEngulfing"; Pv = ((O1>C1) AND
(C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1))); }
   else if(P == 27) { PatternName = "ThreeOutsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1>= O2) AND (C2>= O1) AND ((C1-O1)>(O2-C2)) AND (C>O) AND
(C>C1)); }
   else if(P == 28) { PatternName = "BullishHarami"; Pv = ((O1>C1) AND (C>O)
AND (C<= O1) AND (C1<= O) AND ((C-O)<(O1-C1))); }
   else if(P == 29) { PatternName = "ThreeInsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1<= O2) AND (C2<= O1) AND ((C1-O1)<(O2-C2)) AND (C>O) AND
(C>C1) AND (O>O1)); }
   else if(P == 30) { PatternName = "PiercingLine"; Pv = ((C1<O1) AND
(((O1+C1)/2)<C) AND (O<C) AND (O<C1) AND (C<O1) AND
((C-O)/(.001+(H-L))>0.6)); }
   else if(P == 31) { PatternName = "BearishHarami"; Pv = ((C1>O1) AND (O>C)
AND (O<= C1) AND (O1<= C) AND ((O-C)<(C1-O1))); }
   else if(P == 32) { PatternName = "ThreeInsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1<= C2) AND (O2<= C1) AND ((O1-C1)<(C2-O2)) AND (O>C) AND
(C<C1) AND (O<O1)); }
   else if(P == 33) { PatternName = "ThreeWhiteSoldiers"; Pv = (C>O*1.01)
AND (C1>O1*1.01) AND (C2>O2*1.01) AND (C>C1) AND (C1>C2) AND (O<C1) AND
(O>O1) AND (O1<C2) AND (O1>O2) AND (((H-C)/(H-L))<.2) AND
(((H1-C1)/(H1-L1))<.2) AND (((H2-C2)/(H2-L2))<.2); }
   else if(P == 34) { PatternName = "DarkCloudCover"; Pv = (C1>O1*1.01) AND
(O>C) AND (O>H1) AND (C>O1) AND (((C1+O1)/2)>C) AND (C>O1) AND
(MA(C,13)-Ref(MA(C,13),-4)>0); }
   else if(P == 35) { PatternName = "ThreeBlackCrows"; Pv = (O>C*1.01) AND
(O1>C1*1.01) AND (O2>C2*1.01) AND (C<C1) AND (C1<C2) AND (O>C1) AND (O<O1)
AND (O1>C2) AND (O1<O2) AND (((C-L)/(H-L))<.2) AND (((C1-L1)/(H1-L1))<.2)
AND (((C2-L2)/(H2-L2))<.2); }
   else if(P == 36) { PatternName = "doji"; Pv = (O == C); }
   else if(P == 37) { PatternName = "GapUp"; Pv = GapUp(); }
   else if(P == 38) { PatternName = "GapDown"; Pv = GapDown(); }
   else if(P == 39) { PatternName = "BigGapUp"; Pv = L>1.01*H1; }
   else if(P == 40) { PatternName = "BigGapDown"; Pv = H<0.99*L1; }
   else if(P == 41) { PatternName = "HugeGapUp"; Pv = L>1.02*H1; }
   else if(P == 42) { PatternName = "HugeGapDown"; Pv = H<0.98*L1; }
   else if(P == 43) { PatternName = "DoubleGapUp"; Pv = GapUp() AND
Ref(GapUp(),-1); }
   else if(P == 44) { PatternName = "DoubleGapDown"; Pv = GapDown() AND
Ref(GapDown(),-1); }
   return Pv;
   }

PatternNameList = "";
for(Cp=0; Cp<=44; Cp++)
	{
	VarSet("Pattern"+NumToStr(Cp,1.0),CandlePattern(cP));
	PatternNameList = PatternNameList +PatternName+","; 
	}

BI = BarIndex();
SelectedBar = SelectedValue(BI) -BI[0];
//Selectedbar = Status("lastvisiblebar")-1;
PStr="";
for(Cp=0; Cp<=44; Cp++)
	{
	Temp = VarGet("Pattern"+NumToStr(Cp,1.0));
	if(temp[SelectedBar]) Pstr=Pstr+"#"+NumToStr(Cp,1.0)+" - "+StrExtract(PatternNameList,Cp)+"\n";
	}


FS=Param("Font Size",11,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor( ParamColor("Color",colorWhite) ); 
Hor=Param("Horizontal Position",237,1,1200,1);
Ver=Param("Vertical Position",50,1,830,1); 
GfxTextOut("Candle Reader= "+Pstr, Hor , Ver );





_SECTION_END();
 
#8
Sorry to Interrupt Johnny,

I have tested ur Stochastic on nifty.. i didnt found it useful.

Rather then i found it more useful...

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

Good to find divergence too..
 

johnnypareek

Well-Known Member
#9
Hey Shruti,

Happy that you are exploring nicely. Okay here is another version.

What I want to tell you that plot this on 30m TF or hrly TF and do one stupid thing, it will look like stupid which I am going to write, Mark high of the bar who push it to cross 70. When price cross that high buy . Chk out this on axis spot 30 min

HTML:
Periods=Param("Periods",8,3,70,2);
SmoothFactor = Param("SM",3,3,14,1);
Levelup= 70;
Leveldown=30;
R= RSI(Periods);
StochR=100*(R-LLV(R,periods))/(HHV(R,periods)-LLV(R,periods));
SR=EMA(StochR,SmoothFactor);
Buy= Cross( SR,Leveldown);
Sell= Cross(Levelup,SR);
Short=Sell;
Cover=Buy;
Buy= ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
PH =30; 
RHeight = 100/PH*100;
GraphXSpace = 1*PH;
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
Plot(0,"",colorBlack,styleDashed|styleOwnScale,0,RHeight);
Plot(SR,"   RSI Value ",4,styleThick|styleOwnScale,0,RHeight);
Plot(Levelup,"     LevelUP ",colorPlum,styleDashed|styleOwnScale,0,RHeight);
Plot(Leveldown,"    Level Down",colorBlue,styleDashed|styleOwnScale,0,RHeight);
Plot(100,"",colorBlack,styleThick|styleOwnScale,0,RHeight);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
 
#10
Dear Johnny ,
Nice Logic n found it really helpful.
But it will be of Great ease if you plot buy/sell arrows according to condition mention below-

1)Please remove all buy/sell Old arrows plotted on price chart.

2)Buy should come when Stochastic crosses above 70 (Buy arrow should be visible on Particular price bar) vice-versa for Sell once below 30 (Sell arrow should be visible on particular Price bar).

3) Please provide (Star marking) for Exit Trade.

4) How one should exit once trade.kindly help.
(My view - is it once price crosses 70 from top and 30 from below ??) ... pls plot according to ur view.

5) pls add exploration to it.

Waiting for ur reply.

Thanx you in advance.
 
Last edited: