//@Name:2 MACD Indicators //@Description:Draws two MACDs so that they use the same scale on the indicator panel, whereas adding two seperately within the program will not. // 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. //variables stored in store1 var signal1 = 1; var longMAperiod1 = 26; var shortMAperiod1 = 13; //variables stored in store2 var longMAperiod2 = 26; var shortMAperiod2 = 13; var signal2 = 1; //variables stored in store3 var style1 = 0 var signalPeriod1 = 9; var signalPeriod2 = 9; var colour1 = Colour.Red; var colour2 = Colour.Red; var colour3 = Colour.Blue; var colour4 = Colour.Blue; //variable stored in store4 var style2 = 1; var style3 = 0; var style4 = 1; var width1 = 0; var width2 = 0; var width3 = 0; var width4 = 0; var store1; var store2; var store3; var store4; function init(status) { if (status == Loading || status == Editing) { colour1 = storage.getAt(0); colour2 = storage.getAt(1); colour3 = storage.getAt(2); colour4 = storage.getAt(3); store1 = storage.getAt(4); store2 = storage.getAt(5); store3 = storage.getAt(6); store4 = storage.getAt(7); store1 = store1.toString(); signal1=parseInt(store1.substr(0,1),10)-1; longMAperiod1=parseInt(store1.substr(1,3),10); shortMAperiod1=parseInt(store1.substr(4,3),10); store2 = store2.toString(); signal2 = parseInt(store2.substr(0,1),10)-1; longMAperiod2 = parseInt(store2.substr(1,3),10); shortMAperiod2 = parseInt(store2.substr(4,3),10); store3 = store3.toString(); style1 = parseInt(store3.substr(0,1),10)-1; signalPeriod1 = parseInt(store3.substr(1,3),10); signalPeriod2 = parseInt(store3.substr(4,3),10); store4 = store4.toString(); style2 = parseInt(store4.substr(0,1),10)-1; style3 = parseInt(store4.substr(1,1),10)-1; style4 = parseInt(store4.substr(2,1),10)-1; width1 = parseInt(store4.substr(3,1),10)-1; width2 = parseInt(store4.substr(4,1),10)-1; width3 = parseInt(store4.substr(5,1),10)-1; width4 = parseInt(store4.substr(6,1),10)-1; } if (status == Adding || status == Editing) { dlg = new Dialog((status==Adding?"Add":"Edit")+" indicator", 220, 110); dlg.addOkButton(); dlg.addCancelButton(); dlg.addGroupBox(5,5,150,25,"First MACD Properties"); dlg.addIntEdit("VAL8",20,15,-1,-1,""," and ",shortMAperiod1,2,999); dlg.addIntEdit("VAL7",70,15,-1,-1,"","",longMAperiod1,2,999); dlg.addColLinePicker("VAL1",120,13,-1,-1,"","",colour1,style1,width1); dlg.addGroupBox(5,30,150,25,""); dlg.addTickBox("VAL5",8,30,65,-1,"Signal Properties",signal1); dlg.addColLinePicker("VAL2",120,38,-1,-1,"","",colour2,style2,width2); dlg.addIntEdit("VAL9",20,40,-1,-1,"","",signalPeriod1,2,999); dlg.addGroupBox(5,55,150,25,"Second MACD Properties"); dlg.addIntEdit("VAL11",20,65,-1,-1,""," and ",shortMAperiod2,2,999); dlg.addIntEdit("VAL10",70,65,-1,-1,"","",longMAperiod2,2,999); dlg.addColLinePicker("VAL3",120,63,-1,-1,"","",colour3,style3,width3); dlg.addGroupBox(5,80,150,25,""); dlg.addTickBox("VAL6",8,80,65,-1,"Signal Properties",signal2); dlg.addIntEdit("VAL12",20,90,-1,-1,"","",signalPeriod2,2,999); dlg.addColLinePicker("VAL4",120,88,-1,-1,"","",colour4,style4,width4); if (dlg.show()==Dialog.Cancel) return false; colour1 = dlg.getValue("VAL1").colour; style1 = dlg.getValue("VAL1").pen; width1 = dlg.getValue("VAL1").width; colour2 = dlg.getValue("VAL2").colour; style2 = dlg.getValue("VAL2").pen; width2 = dlg.getValue("VAL2").width; colour3 = dlg.getValue("VAL3").colour; style3 = dlg.getValue("VAL3").pen; width3 = dlg.getValue("VAL3").width; colour4 = dlg.getValue("VAL4").colour; style4 = dlg.getValue("VAL4").pen; width4 = dlg.getValue("VAL4").width; signal1 = dlg.getValue("VAL5"); signal2 = dlg.getValue("VAL6"); longMAperiod1 = dlg.getValue("VAL7"); shortMAperiod1 = dlg.getValue("VAL8"); signalPeriod1 = dlg.getValue("VAL9"); longMAperiod2 = dlg.getValue("VAL10"); shortMAperiod2 = dlg.getValue("VAL11"); signalPeriod2 = dlg.getValue("VAL12"); store1 = (signal1+1)*1000000+longMAperiod1*1000+shortMAperiod1; store2 = (signal2+1)*1000000+longMAperiod2*1000+shortMAperiod2; store3 = (style1+1)*1000000+signalPeriod1*1000+signalPeriod2 ; store4 = (style2+1)*1000000+(style3+1)*100000+(style4+1)*10000+(width1+1)*1000+(width2+1)*100+(width3+1)*10+(width4+1); storage.setAt(0, colour1); storage.setAt(1, colour2); storage.setAt(2, colour3); storage.setAt(3, colour4); storage.setAt(4, store1); storage.setAt(5, store2); storage.setAt(6, store3); storage.setAt(7, store4); } setTitle("MACD 1 ("+longMAperiod1+","+shortMAperiod1+","+signalPeriod1+") MACD 2 ("+longMAperiod2+","+shortMAperiod2+","+signalPeriod2+")"); setSeriesColour(0, colour1); setSeriesLineStyle(0,style1,width1); setSeriesColour(1, colour3); setSeriesLineStyle(1,style3,width3); if (signal1) { setSeriesColour(2, colour2); setSeriesLineStyle(2,style2,width2); } if (signal2) { setSeriesColour(3, colour4); setSeriesLineStyle(3,style4,width4); } setRange(Range.CentreZero); setHorizontalLine(0); } function getGraph(share, data) { var MACD1ma1 = new MA(longMAperiod1, MA.Exponential); var MACD1ma2 = new MA(shortMAperiod1, MA.Exponential); var signal_ma1 = new MA(signalPeriod1, MA.Exponential); var MACD2ma1 = new MA(longMAperiod2, MA.Exponential); var MACD2ma2 = new MA(shortMAperiod2, MA.Exponential); var signal_ma2 = new MA(signalPeriod2, MA.Exponential); var mainLine1 = new Array(); var signalLine1 = new Array(); var mainLine2 = new Array(); var signalLine2 = new Array(); for (var i=0; i