//@LibraryID:881,1 //@Name:Intraday Pivot Points //@Description: Draws Pivot Points based on the 4 hourly or 1 hourly close //@Env:Production //@Type:Intraday // 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. // Coded by: Phil Tolhurst, ShareScope Support var colour1 = 16711680; var colour2 = 65025; var colour3 = 255; var colour4 = 255; var pen1 = 0; var pen2 = 1; var pen3 = 2; var pen4 = 3; var width1 = 0; var width2 = 0; var width3 = 0; var width4 = 0; var dataList = ["4 hr","1 hr"]; var dataChoice = 0; var ppSwitch = 1; var sup1Switch =1; var sup2Switch =1; var sup3Switch =1; var res1Switch =1; var res2Switch =1; var res3Switch =1; var show = 1; //Draws the Dialog box and stores the values set so that they can be recalled either when starting the program or when edditing the indicator. function init(status) { if (status == Loading || status == Editing) { pen1 = storage.getAt(0); pen2 = storage.getAt(1); pen3 = storage.getAt(2); pen4 = storage.getAt(3); width1 = storage.getAt(4); width2 = storage.getAt(5); width3 = storage.getAt(6); width4 = storage.getAt(7); colour1 = storage.getAt(8); colour2 = storage.getAt(9); colour3 = storage.getAt(10); colour4 = storage.getAt(11); dataChoice = storage.getAt(12); ppSwitch = storage.getAt(13); sup1Switch = storage.getAt(14); sup2Switch = storage.getAt(15); sup3Switch = storage.getAt(16); res1Switch = storage.getAt(17); res2Switch = storage.getAt(18); res3Switch = storage.getAt(19); } if (status == Adding || status == Editing) { var dlg = new Dialog("Pivot Line Settings...", 230, 120); dlg.addOkButton(); dlg.addCancelButton(); dlg.addGroupBox(5,5,135,110,"Line Properties"); dlg.addColLinePicker("VAL1",100,15,-1,-1,"Pivot Point","",colour1,pen1,width1); dlg.addColLinePicker("VAL2",100,35,-1,-1,"First Support/Resistance","",colour2,pen2,width2); dlg.addColLinePicker("VAL3",100,55,-1,-1,"Second Support/Resistance","",colour3,pen3,width3); dlg.addColLinePicker("VAL4",100,75,-1,-1,"Third Support/Resistance","",colour4,pen4,width4); dlg.addDropList("VAL5",70,95,-1,-1,dataList,"Choose data type:","",dataChoice); dlg.addGroupBox(145,40,80,75,"Draw"); dlg.addTickBox("VAL6",150,50,30,-1,"PP",ppSwitch); dlg.addTickBox("VAL7",150,67,30,-1,"Sup1",sup1Switch); dlg.addTickBox("VAL8",150,84,30,-1,"Sup2",sup2Switch); dlg.addTickBox("VAL9",150,101,30,-1,"Sup3",sup3Switch); dlg.addTickBox("VAL10",190,67,30,-1,"Res1",res1Switch); dlg.addTickBox("VAL11",190,84,30,-1,"Res2",res2Switch); dlg.addTickBox("VAL12",190,101,30,-1,"Res3",res3Switch); if (dlg.show() == Dialog.Cancel) return false; colour1 = dlg.getValue("VAL1").colour; pen1 = dlg.getValue("VAL1").pen; width1 = dlg.getValue("VAL1").width; colour2 = dlg.getValue("VAL2").colour; pen2 = dlg.getValue("VAL2").pen; width2 = dlg.getValue("VAL2").width; colour3 = dlg.getValue("VAL3").colour; pen3 = dlg.getValue("VAL3").pen; width3 = dlg.getValue("VAL3").width; colour4 = dlg.getValue("VAL4").colour; pen4 = dlg.getValue("VAL4").pen; width4 = dlg.getValue("VAL4").width; dataChoice = dlg.getValue("VAL5"); ppSwitch = dlg.getValue("VAL6"); sup1Switch = dlg.getValue("VAL7"); sup2Switch = dlg.getValue("VAL8"); sup3Switch = dlg.getValue("VAL9"); res1Switch = dlg.getValue("VAL10"); res2Switch = dlg.getValue("VAL11"); res3Switch = dlg.getValue("VAL12"); storage.setAt(0, pen1); storage.setAt(1, pen2); storage.setAt(2, pen3); storage.setAt(3, pen4); storage.setAt(4, width1); storage.setAt(5, width2); storage.setAt(6, width3); storage.setAt(7, width4); storage.setAt(8, colour1); storage.setAt(9, colour2); storage.setAt(10, colour3); storage.setAt(11, colour4); storage.setAt(12,dataChoice); storage.setAt(13,ppSwitch); storage.setAt(14,sup1Switch); storage.setAt(15,sup2Switch); storage.setAt(16,sup3Switch); storage.setAt(17,res1Switch); storage.setAt(18,res2Switch); storage.setAt(19,res3Switch); } buttonHandle = createButton("Settings....", onButton0); buttonHandle = createButton("Off", onButton1); } function onButton0() { dialog() } function onButton1() { if (show==1) { show = 0; clearDisplay(); setButtonText(1, "On"); } else if(show==0) { show=1; setButtonText(1,"Off"); draw(); } } function onNewChart() { clearDisplay(); if (show==1)draw(); } function onNewBar() { clearDisplay(); if (show==1)draw(); } function draw() { var pivot=0; var res1=0; var res2=0; var sup1=0; var sup2=0; var res3=0; var sup3=0; if (dataChoice == 0) { var yesterdaysData = getCurrentShare().getIBarArray(1,14400); var todaysData = getCurrentShare().getIBarArray(0,14400); var data = yesterdaysData.concat(todaysData); if(data==undefined || data.length<2) { pivot = 0; res1 = 0; sup1 = 0; res2 = 0; sup2 = 0; res3 = 0; sup3 = 0; } else { var price = data[data.length-2] pivot = (price.high + price.low + price.close) / 3 res1 = pivot + (pivot - price.low); sup1 = pivot - (price.high - pivot); res2 = pivot + (price.high - price.low); sup2 = pivot - (price.high - price.low); res3 = pivot + 2*(price.high - price.low); sup3 = pivot - 2*(price.high - price.low); } } else { var yesterdaysData = getCurrentShare().getIBarArray(1,3600); var todaysData = getCurrentShare().getIBarArray(0,3600); var data = yesterdaysData.concat(todaysData); if(data==undefined || data.length<2) { pivot = 0; res1 = 0; sup1 = 0; res2 = 0; sup2 = 0; res3 = 0; sup3 = 0; } else { var price = data[data.length-2] pivot = (price.high + price.low + price.close) / 3 res1 = pivot + (pivot - price.low); sup1 = pivot - (price.high - pivot); res2 = pivot + (price.high - price.low); sup2 = pivot - (price.high - price.low); res3 = pivot + 2*(price.high - price.low); sup3 = pivot - 2*(price.high - price.low); } } if (ppSwitch==1) { setPenStyle(pen1,width1,colour1); beginPath(); for (var i=0;i