//@Name:MACD % change //@Description:Displays the percentage change between the last two values of the MACD, signal or histogram. //@Returns:Number //@Width:80 //@Env:Production // 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 shortPeriod = 13; var longPeriod = 26; var signalPeriod = 9; var outputList = ["MACD","Signal","Histogram"]; var dataList = ["Daily","Weekly","Monthly"]; var dataSource = 0; var outputType = 0; var outptut = 0; var daysAgo1 = 0; var daysAgo2 = 5; function init(status) { if (status == Loading || status == Editing) { outputType = storage.getAt(0); shortPeriod = storage.getAt(1); longPeriod = storage.getAt(2); signalPeriod = storage.getAt(3); dataSource = storage.getAt(4); daysAgo1 = storage.getAt(5); daysAgo2 = storage.getAt(6); } if (status == Adding || status == Editing) { dlg = new Dialog("MACD settings",240,110); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,5,65,-1,outputList,"","",outputType); dlg.addIntEdit("INT1",8,22,-1,-1,"","short period",shortPeriod,2,1000); dlg.addIntEdit("INT2",8,39,-1,-1,"","long period",longPeriod,3,1000); dlg.addIntEdit("INT3",8,56,-1,-1,"","signal period",signalPeriod,2,1000); dlg.addDropList("DL2",8,73,65,-1,dataList,"","",dataSource); dlg.addIntEdit("INT4",73,90,-1,-1,"% change between","periods ago",daysAgo1); dlg.addIntEdit("INT5",160,90,-1,-1,"and","periods ago",daysAgo2); if (dlg.show()==Dialog.Cancel) return false; outputType = dlg.getValue("DL1"); shortPeriod = dlg.getValue("INT1"); longPeriod = dlg.getValue("INT2"); signalPeriod = dlg.getValue("INT3"); dataSource = dlg.getValue("DL2"); daysAgo1 = dlg.getValue("INT4"); daysAgo2 = dlg.getValue("INT5"); storage.setAt(0, outputType); storage.setAt(1, shortPeriod); storage.setAt(2, longPeriod); storage.setAt(3, signalPeriod); storage.setAt(4, dataSource); storage.setAt(5, daysAgo1); storage.setAt(6, daysAgo2); } //sets the title of the column setTitle((outputType==0?"":"MACD ")+outputList[outputType]+": "+shortPeriod+","+longPeriod+","+signalPeriod+" ("+dataList[dataSource]+") %change between "+daysAgo1+" & "+daysAgo2+" periods ago") } function getVal(share) { if (dataSource==0) var data = share.getPriceArray(longPeriod*6); if (dataSource==1) var data = share.getWeeklyBarArray(longPeriod*6); if (dataSource==2) var data = share.getMonthlyBarArray(longPeriod*6); var macd1 = new MACD(shortPeriod,longPeriod,signalPeriod); var mainRes = []; var signalRes = []; var histoRes = []; for (var i=0;i