//@LibraryID:1250,0 //@Name:Volume Positive Negative (VPN) indicator //@Description:Plots Volume Positive Negative (VPN) indicator. Above a certain critical value (buy signal value) is bullish and negative values are bearish. var sigPeriod = 30; var sigTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA"]; var buyVal = 10; var volCol = Colour.Black; var volStyle = Pen.Solid; var volWidth = 0; function init(status) { if (status == Loading || status == Editing) { sigPeriod = storage.getAt(0); buyVal = storage.getAt(1); volCol = storage.getAt(2); volStyle = storage.getAt(3); volWidth = storage.getAt(4); } if (status == Adding || status == Editing) { dlg = new Dialog((status==Adding?"Add":"Edit")+" VPN indicator...", 245, 50); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",130,7,-1,-1,"Period: ","",sigPeriod,2,5000); dlg.addIntEdit("VAL2",72,26,-1,-1,"Buy signal level: ","",buyVal,0,100); dlg.addColLinePicker("VAL3",65,5,-1,-1,"Indicator line: ","",volCol,volStyle,volWidth); if (dlg.show()==Dialog.Cancel) return false; sigPeriod = dlg.getValue("VAL1"); buyVal = dlg.getValue("VAL2"); volCol = dlg.getValue("VAL3").colour; volStyle = dlg.getValue("VAL3").pen; volWidth= dlg.getValue("VAL3").width; storage.setAt(0, sigPeriod); storage.setAt(1, buyVal); storage.setAt(2, volCol); storage.setAt(3, volStyle); storage.setAt(4, volWidth); } setSeriesColour(0,volCol); setSeriesLineStyle(0,volStyle,volWidth); setTitle("VPN (Period:"+sigPeriod+")"); setSeriesColour(1,Colour.Red); setSeriesColour(2,Colour.Green); } function getGraph(share, data) { if (data.lengthi-sigPeriod; j--) { atrRes = atrCalc.getNext(share.getPrice(j)); try { yestAvPrice=(data[j-1].close+data[j-1].open+data[j-1].high +data[j-1].low)/4; } catch(e) { try { yestAvPrice=(data[j-2].close+data[j-2].open+data[j-2].high +data[j-2].low)/4; } catch(e) { try { yestAvPrice=(data[j-3].close+data[j-3].open+data[j-3].high +data[j-3].low)/4 } catch(e) { continue } } } try { todayAvPrice=(data[j].close+data[j].open+data[j].high+data[j].low)/4 perOfATR = Math.abs(todayAvPrice-yestAvPrice)/atrRes if (todayAvPrice > yestAvPrice && perOfATR>0.1) { upSum += data[j].volume } else if (todayAvPrice < yestAvPrice && perOfATR>0.1) { downSum += data[j].volume } else { continue } } catch(e) { continue } } if (data[i].volume>0) { sigRes[i] = sigCalc.getNext(data[i].volume); VPNvalue[i] = ((upSum-downSum)/sigRes[i])*(100/sigPeriod); } else { VPNvalue[i]=VPNvalue[i-1] } } var finalVPNvalue = []; var zeroLine=[]; var buyLine=[]; for (var i=sigPeriod; i