//@Name:MACD Bars //@Description:Colours the graph bars based on a choice of MACD values. // 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: Richard Chiesa, ShareScript Support var outputType = 0; var sp = 13; var lp = 26; var sigp = 9; var upCol = Colour.DarkGreen; var downCol = Colour.Red; function init(status) { if (status == Loading || status == Editing) { outputType = storage.getAt(0); sp = storage.getAt(1); lp = storage.getAt(2); sigp = storage.getAt(3); upCol = storage.getAt(4); downCol = storage.getAt(5); } if (status == Adding || status == Editing) { dlg = new Dialog("Set colours", 150, 105); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,80,-1,["MACD pos/neg","MACD up/down","Histogram pos/neg","Histogram up/down"],"","",outputType); dlg.addIntEdit("INT1",8,-1,-1,-1,"","short period",sp,2,1000); dlg.addIntEdit("INT2",8,-1,-1,-1,"","long period",lp,3,1000); dlg.addIntEdit("INT3",8,-1,-1,-1,"","signal period",sigp,2,1000); dlg.addColPicker("COL1",8,-1,-1,-1, "","Up colour",upCol); dlg.addColPicker("COL2",8,-1,-1,-1, "","Down colour",downCol); if (dlg.show()==Dialog.Cancel) return false; outputType = dlg.getValue("DL1"); sp = dlg.getValue("INT1"); lp = dlg.getValue("INT2"); sigp = dlg.getValue("INT3"); upCol = dlg.getValue("COL1"); downCol = dlg.getValue("COL2"); storage.setAt(0, outputType); storage.setAt(1, sp); storage.setAt(2, lp); storage.setAt(3, sigp); storage.setAt(4, upCol); storage.setAt(5, downCol); } setTitle(sp+", "+lp+" MACD ("+sigp+" sig.)"); } function onNewBarUpdate() { onNewChart(); } function onNewChart() { clearDisplay(); if (bars.length<2) return; var macd1 = new MACD(sp,lp,sigp); var main = []; var signal = []; var hist = []; for (var i=0;i=0) || (outputType==1 && main[i]>=main[i-1] || (outputType==2 && hist[i]>=0) || (outputType==3 && hist[i]>=hist[i-1]))) { bars[i].colour = upCol; } else { bars[i].colour = downCol; } } }