//@Name:PivotPointMA //@Description: A moving average based on pivot points instead of close prices //Author: ShareScript Support //This script will calculate a share's moving average using pivot points //instead of close prices. You can change the periods and type of MA and the //pivot point calculation method to suit your needs. var maPeriod = 20; var maType = 1; var maTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA"]; var maList = ["Simple","Exponential","Weighted","Triangular","VariableVHF","VariableCMO","VIDYA"]; var ppType = 0; //Calculation method 0=Trad; 1=Var.1; 2=Var.2; var ppList = ["Traditional","Var.1","Var.2"]; var maColour = Colour.Red; var maPen = 0; var maWidth = 0; function init(status) { if (status == Loading || status == Editing) { maPeriod = storage.getAt(0); maType = storage.getAt(1); ppType = storage.getAt(2); maColour = storage.getAt(3); maPen = storage.getAt(4); maWidth = storage.getAt(5); if (maPeriod == undefined) maPeriod=20; if (maType == undefined) maType=0; if (ppType == undefined) ppType=0; if (maColour == undefined) maColour=Colour.Red; if (maPen == undefined) maPen = 0; if (maWidth == undefined) maWidth = 0; } if (status == Adding || status == Editing) { dlg = new Dialog("Settings...",250,80); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("VAL1",55,5,-1,-1,maList,"","",maType); dlg.addIntEdit("VAL2",20,5,-1,-1,"MA:","",maPeriod,2,1000); dlg.addColLinePicker("VAL3",125,5,-1,-1,"","",maColour,maPen,maWidth); dlg.addDropList("VAL4",36,22,-1,-1,ppList,"PP Type:","",ppType); dlg.addText(5,40,150,10,"Traditional = (High+Low+Close)/3"); dlg.addText(5,52,150,10,"Var.1 = (High+Low+Close+Open)/4"); dlg.addText(5,64,150,10,"Var.2 = (High+Low+Open)/3"); if (dlg.show()==Dialog.Cancel) return false; maType = dlg.getValue("VAL1"); maPeriod = dlg.getValue("VAL2"); maColour = dlg.getValue("VAL3").colour; maPen = dlg.getValue("VAL3").pen; maWidth = dlg.getValue("VAL3").width; ppType = dlg.getValue("VAL4") storage.setAt(0, maPeriod); storage.setAt(1, maType); storage.setAt(2, ppType); storage.setAt(3, maColour); storage.setAt(4, maPen); storage.setAt(5, maWidth); } setRange(Range.Parent); setSeriesColour(0, maColour); setSeriesLineStyle(0,maPen,maWidth); setTitle(maPeriod+maTitleList[maType]+" "+ppList[ppType]); } function getGraph(share, data) { var pivotMA = new Array(); var ma1 = new MA(maPeriod, maType); //Moving average period and type var pivot = 0; for (i=1; i