//@Name:MA ROC % //@Description:Returns the percentage rate of change of a chosen MA //@Env:Production // 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 var1 = 20; var var2 = 1; var MAtype1 = 0; var maList = ["Simple","Exponential","Weighted","Triangular","VariableVHF","VariableCMO","VIDYA"]; var maTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA"]; var lineCol = Colour.Red; var lineStyle = Pen.Solid var lineWidth = 1; function init(status) { if (status == Loading || status == Editing) { MAtype1 = storage.getAt(0) var1 = storage.getAt(1); var2 = storage.getAt(2); lineCol = storage.getAt(3); lineStyle = storage.getAt(4); lineWidth = storage.getAt(5); } if (status == Adding || status == Editing) { dlg = new Dialog("MA ROC%...",160,75); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL2",8,-1,80,-1,maList,"","",MAtype1); dlg.addIntEdit("INT2",8,-1,-1,-1,"","Period",var1,2,1000); dlg.addIntEdit("INT3",8,-1,-1,-1,"","ROC period",var2,1,500); dlg.addColLinePicker("LN1",8,-1,-1,-1,"","",lineCol,lineStyle,lineWidth); if (dlg.show()==Dialog.Cancel) return false; MAtype1 = dlg.getValue("DL2"); var1 = dlg.getValue("INT2"); var2 = dlg.getValue("INT3"); lineCol = dlg.getValue("LN1").colour; lineStyle = dlg.getValue("LN1").pen; lineWidth = dlg.getValue("LN1").width; storage.setAt(0, MAtype1); storage.setAt(1, var1); storage.setAt(2, var2); storage.setAt(3, lineCol); storage.setAt(4, lineStyle); storage.setAt(5, lineWidth); } setTitle(var1+" "+maTitleList[MAtype1]+" ("+var2+" ROC%)"); setSeriesColour(0, lineCol); setSeriesLineStyle(0, lineStyle, lineWidth); } function getGraph(share, data) { var ma1 = new MA(var1,MAtype1); var line1 = []; var output = []; for (var i=0;i0) output[i] = (line1[i] / line1[i-var2] - 1)*100; } return output; }