//@LibraryID:1143,0 //@Name:Qstick //@Description: The Qstick indicator (by Tushar Chande) //Author: Paul Hall, ShareScope Support // 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 period = 20; var indCol = Colour.Blue; var indStyle = Pen.Solid; var indWidth = 0; var sigPeriod = 9; var sigType = 0; var sigList = ["Simple","Exponential","Weighted","Triangular"]; var sigList2 = ["SMA","EMA","WMA","TMA"]; var sigTick = 0; var sigCol = Colour.Red; var sigStyle = Pen.Dash; var sigWidth = 0; function init(status) { if (status == Loading || status == Editing) { var store1 = restore(storage.getAt(0), [[sigType,0,3],[sigTick,0,1],[sigStyle,0,4],[sigWidth,0,7],[indStyle,0,4],[indWidth,0,7]]) period = storage.getAt(1); sigPeriod = storage.getAt(2); indCol = storage.getAt(3); sigCol = storage.getAt(4); sigType = store1[0][0]; sigTick = store1[1][0]; sigStyle = store1[2][0]; sigWidth = store1[3][0]; indStyle = store1[4][0]; indWidth = store1[5][0]; } if (status == Adding || status == Editing) { dlg = new Dialog((status==Adding?"Add":"Edit")+" Qstick indicator",270,55); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",45,5,-1,-1,"Qstick:","period",period,2,5000); dlg.addColLinePicker("VAL2",105,5,-1,-1,"","",indCol,indStyle,indWidth); dlg.addIntEdit("VAL3",45,25,-1,-1,"Signal:","period",sigPeriod,2,5000); dlg.addColLinePicker("VAL4",170,25,-1,-1,"","",sigCol,sigStyle,sigWidth); dlg.addDropList("VAL5",105,25,55,-1,sigList,"","",sigType); dlg.addTickBox("VAL6",8,26,10,10,"",sigTick); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("VAL1"); indCol = dlg.getValue("VAL2").colour; indStyle = dlg.getValue("VAL2").pen; indWidth = dlg.getValue("VAL2").width; sigPeriod = dlg.getValue("VAL3"); sigCol = dlg.getValue("VAL4").colour; sigStyle = dlg.getValue("VAL4").pen; sigWidth = dlg.getValue("VAL4").width; sigType = dlg.getValue("VAL5"); sigTick = dlg.getValue("VAL6"); storage.setAt(0, compress([[sigType,0,3],[sigTick,0,1],[sigStyle,0,4],[sigWidth,0,7],[indStyle,0,4],[indWidth,0,7]])); storage.setAt(1, period); storage.setAt(2, sigPeriod); storage.setAt(3, indCol); storage.setAt(4, sigCol); } setSeriesColour(0,indCol); setSeriesLineStyle(0,indStyle,indWidth); setSeriesColour(1,sigCol); setSeriesLineStyle(1,sigStyle,sigWidth); if(sigTick==1) setTitle(period+" Qstick (sig: "+sigPeriod+sigList2[sigType]+")"); else setTitle(period+" Qstick"); } function getGraph(share, data) { var qStick = new Array(); var signal = new Array(); var ma1 = new MA(period); var ma2 = new MA(sigPeriod,sigType); for (var i=0; i8388608) print("Too much data for single storage space") return output } function restore(storage, data) { var remainder = storage var rangeTot = 1 for (var i=0;i=0;i--) { if (i