//@Name:Stoch RSI //@Description:Draws a Stochastic Oscillator of the RSI. //@Future:Yes // Care has been taken in preparing this code but it is provided without guarantee. // You are welcome to modify and extend it. Please add your name as a modifier if you distribute it. var rsiPeriod = 20; var stochPeriod = 20; var stochSlow = 2; var stochSignal = 9; var lineCol1 = Colour.RGB(0,200,200); var lineStyle1 = Pen.Solid; var lineWidth1 = 1; var lineCol2 = Colour.RGB(0,200,200); var lineStyle2 = Pen.Dot; var lineWidth2 = 0; function init(status) { if (status == Loading || status == Editing) { rsiPeriod = storage.getAt(0); stochPeriod = storage.getAt(1); stochSlow = storage.getAt(2); stochSignal = storage.getAt(3); lineCol1 = storage.getAt(4); lineCol2 = storage.getAt(5); var totalLine = storage.getAt(6); totalLine=totalLine.toString(); lineStyle1=parseInt(totalLine.substr(1,1),10); lineWidth1=parseInt(totalLine.substr(2,1),10); lineStyle2=parseInt(totalLine.substr(3,1),10); lineWidth2=parseInt(totalLine.substr(4,1),10); } if (status == Adding || status == Editing) { var dlg = new Dialog("Stoch RSI",170,110); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,-1,-1,-1,"","RSI period",rsiPeriod,2,1000); dlg.addIntEdit("INT2",8,-1,-1,-1,"","Stoch period",stochPeriod,2,1000); dlg.addIntEdit("INT3",8,-1,-1,-1,"","Slowing period",stochSlow,1,1000); dlg.addIntEdit("INT4",8,-1,-1,-1,"","Signal period",stochSignal,2,1000); dlg.addColLinePicker("LN1",8,-1,-1,-1,"","Stochastic",lineCol1,lineStyle1,lineWidth1); dlg.addColLinePicker("LN2",8,-1,-1,-1,"","Signal",lineCol2,lineStyle2,lineWidth2); if (dlg.show()==Dialog.Cancel) return false; rsiPeriod = dlg.getValue("INT1"); stochPeriod = dlg.getValue("INT2"); stochSlow = dlg.getValue("INT3"); stochSignal = dlg.getValue("INT4"); lineCol1 = dlg.getValue("LN1").colour; lineStyle1 = dlg.getValue("LN1").pen; lineWidth1 = dlg.getValue("LN1").width; lineCol2 = dlg.getValue("LN2").colour; lineStyle2 = dlg.getValue("LN2").pen; lineWidth2 = dlg.getValue("LN2").width; storage.setAt(0, rsiPeriod); storage.setAt(1, stochPeriod); storage.setAt(2, stochSlow); storage.setAt(3, stochSignal); storage.setAt(4, lineCol1); storage.setAt(5, lineCol2); var totalLine = 10000+lineStyle1*1000+lineWidth1*100+lineStyle2*10+lineWidth2; storage.setAt(6, totalLine); } setTitle(stochPeriod+"("+stochSlow+")"+stochSignal+" Stochastic of "+rsiPeriod+" RSI"); setSeriesLineStyle(0, lineStyle1, lineWidth1); setSeriesColour(0, lineCol1); setSeriesLineStyle(1, lineStyle2, lineWidth2); setSeriesColour(1, lineCol2); setHorizontalLine(75); setHorizontalLine(50); setHorizontalLine(25); } function getGraph(share, data) { var rsi1 = new RSI(rsiPeriod); var stoch1 = new StochOsc(stochPeriod,stochSlow,stochSignal); var main = []; var signal = []; for (var i=0;i