//@LibraryID:761,1 //@Name:MACD Conv/Dive //@Description: Returns a 1 if the MACD is converging with the price and a -1 if it is diverging from the price. //@Returns:Number //@Width:90 // 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 longMAperiod; var shortMAperiod; var signalPeriod; var resultType = 2; var resultList = ["Main","Signal","Histogram"]; function init(status) { longMAperiod = 26; shortMAperiod = 13; signalPeriod = 9; dataSource = 0; dataList = ["Daily","Weekly","Monthly"]; if (status == Loading || status == Editing) { longMAperiod = storage.getAt(0); shortMAperiod = storage.getAt(1); signalPeriod = storage.getAt(2); dataSource = storage.getAt(3); resultType = storage.getAt(4); } if (status == Adding || status == Editing) { var dlg = new Dialog("Enter MACD and Signal Values", 200, 90); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1", 65, -1, -1, -1, "Long MA Period","Days",longMAperiod,2,1000); dlg.addIntEdit("VAL2", 65, -1, -1, -1, "Short MA Period","Days",shortMAperiod,2,1000); dlg.addIntEdit("VAL3", 65, -1, -1, -1, "Signal Period","",signalPeriod,2,1000); dlg.addDropList("VAL4", 65, -1, -1, -1, dataList,"","",dataSource); dlg.addDropList("VAL5", 65, -1, -1, -1, resultList,"","",resultType); if (dlg.show() == Dialog.Ok) { longMAperiod=dlg.getValue("VAL1") shortMAperiod=dlg.getValue("VAL2") signalPeriod=dlg.getValue("VAL3") dataSource=dlg.getValue("VAL4") resultType=dlg.getValue("VAL5") storage.setAt(0, longMAperiod); storage.setAt(1, shortMAperiod); storage.setAt(2, signalPeriod); storage.setAt(3, dataSource); storage.setAt(4, resultType); } else { return false; } } } function getVal(share) { if (dataSource==0) var data=share.getPriceArray(longMAperiod*4); if (dataSource==1) var data=share.getWeeklyBarArray(longMAperiod*4); if (dataSource==2) var data=share.getMonthlyBarArray(longMAperiod*4); if (data.lengthresult[y] && data[t].closedata[y].close) output = -1; return output; }