//@Name:W-M Pivot Points //@Description:Pivot Points calculated on weekly or monthly OHLCV data //@Future:Yes //@Type:Intraday //Author: Richard Chiesa, 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; //weekly or monthly 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); cPivot = storage.getAt(1); cSup1 = storage.getAt(2); cSup2 = storage.getAt(3); cRes1 = storage.getAt(4); cRes2 = storage.getAt(5); } if (status == Adding || status == Editing) { var dlg = new Dialog("Set Pivot Points", 200, 120); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1", 65, -1, -1, -1,["Weekly","Monthly"],"","",dataType); 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"); 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, cPivot); storage.setAt(2, cSup1); storage.setAt(3, cSup2); storage.setAt(4, cRes1); storage.setAt(5, 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) { //get either the weekly or monthly EOD data if (!dataType) var EODdata = share.getWeeklyBarArray(); else var EODdata = share.getMonthlyBarArray(); var pivot = []; var res2 = []; var res1 = []; var sup1 = []; var sup2 = []; //get the current weekday and month weekday = share.getIDate().getDay(); month = share.getIDate().getMonth(); //if the EOD data array is larger than 1 calculate pivot points //else return the mid price if (EODdata.length>1) { //if today is the first day of the week or of the month get the last element of the array //else get the second to last if ((dataType==0 && (weekday==1 || EODdata[EODdata.length-1].date.getDay()==5 || (weekday==2 && EODdata[EODdata.length-1].date.getDay()==4))) || (dataType==1 && month!=EODdata[EODdata.length-1].date.getMonth())) { H = EODdata[EODdata.length-1].high; L = EODdata[EODdata.length-1].low; C = EODdata[EODdata.length-1].close; } else { H = EODdata[EODdata.length-2].high; L = EODdata[EODdata.length-2].low; C = EODdata[EODdata.length-2].close; } //calculate the PP, support and resistance values pivot[0] = (H + L + C)/3; res2[0] = pivot[0] + (H-L); res1[0] = (pivot[0]*2) - L; sup1[0] = (pivot[0]*2) - H; sup2[0] = pivot[0] - (H-L); } else { pivot[0] = share.getIMid(); res2[0] = share.getIMid(); res1[0] = share.getIMid(); sup1[0] = share.getIMid(); sup2[0] = share.getIMid(); } //return the same values for all points of the data array for (var i=1;i