//@Name:W-M Pivot Points //@Description:Pivot Points calculated on weekly or monthly OHLCV data //@Future:Yes //@Type:Historical //Author: ShareScript 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 dataType = 0; var latestOnly = false; var cPivot = Colour.LightBlue; var cSup1 = Colour.Cyan; var cSup2 = Colour.Red; var cRes1 = Colour.Cyan; var cRes2 = Colour.Red; function init(status) { if (status == Loading || status == Editing) { dataType = storage.getAt(0); latestOnly = storage.getAt(1); cPivot = storage.getAt(2); cSup1 = storage.getAt(3); cSup2 = storage.getAt(4); cRes1 = storage.getAt(5); cRes2 = storage.getAt(6); } if (status == Adding || status == Editing) { var dlg = new Dialog("Set Pivot Points", 200, 135); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1", 65, -1, -1, -1,["Weekly","Monthly"],"","",dataType); dlg.addTickBox("TB1",8,-1,95,-1,"Display latest values only",latestOnly) dlg.addColPicker("COL5",65,-1,-1,-1,"Resistance 2","",cRes2); dlg.addColPicker("COL4",65,-1,-1,-1,"Resistance 1","",cRes1); dlg.addColPicker("COL1",65,-1,-1,-1,"Pivot","",cPivot); dlg.addColPicker("COL2",65,-1,-1,-1,"Support 1","",cSup1); dlg.addColPicker("COL3",65,-1,-1,-1,"Support 2","",cSup2); if (dlg.show() == Dialog.Cancel) return false; dataType = dlg.getValue("DL1"); latestOnly = dlg.getValue("TB1"); cPivot = dlg.getValue("COL1"); cSup1 = dlg.getValue("COL2"); cSup2 = dlg.getValue("COL3"); cRes1 = dlg.getValue("COL4"); cRes2 = dlg.getValue("COL5"); storage.setAt(0, dataType); storage.setAt(1, latestOnly); storage.setAt(2, cPivot); storage.setAt(3, cSup1); storage.setAt(4, cSup2); storage.setAt(5, cRes1); storage.setAt(6, cRes2); } setRange(Range.Parent); setSeriesLineStyle(0,Pen.Dot) setSeriesColour(0, cPivot); setSeriesColour(1, cSup1); setSeriesColour(2, cSup2); setSeriesColour(3, cRes1); setSeriesColour(4, cRes2); } function getGraph(share, data) { var pivot = new Array(); var sup1 = new Array(); var sup2 = new Array(); var res1 = new Array(); var res2 = new Array(); var H,L,C,thisMonth,x; var pivotVal=sup1Val=sup2Val=res1Val=res2Val=data[0].close; for (var i=1; i=data.length-1) continue; if (dataType && data[i].date.getMonth()==data[i+1].date.getMonth()) continue; if (!dataType && !(data[i+1].date.getDay()==1 || data[i].date.getDay()==5 || (data[i].date.getDay()==4 && data[i+1].date.getDay()==2))) continue; H=L=C=null; thisMonth = data[i].date.getMonth(); yesterday = data[i].date.getDay(); for (var j=0;i-j>=0 && (dataType ? data[i-j].date.getMonth()==thisMonth : data[i-j].date.getDay()<=yesterday);j++) { yesterday = data[i-j].date.getDay(); if (H == null || H < data[i-j].high) H = data[i-j].high; if (L == null || L > data[i-j].low) L = data[i-j].low; if (C == null) C = data[i-j].close; } pivotVal = (H + L + C)/3; res2Val = pivotVal + (H-L); res1Val = (pivotVal*2) - L; sup1Val = (pivotVal*2) - H; sup2Val = pivotVal - (H-L); } for (var i=data.length; i