//@Name:Impulse System Counter //@Description:The Impulse System as described by A Elder in Come Into My Trading Room. Counts how many consecutive positive or negative periods has the system last registered. //Author: Richard Chiesa, ShareScript Support //Impulse System written to be used with a filter. Returns 1 if the Impulse system is green, -1 if it is currently red and 0 if it is neither of those. // 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 macdShort = 12; //short MACD periods var macdLong = 26; //long MACD periods var macdSignal = 9; //MACD signal periods var maPeriods = 13; //exponential moving average periods var dataList = ["Daily","Weekly","Monthly"]; var dataSource = 0; //Variable set by the choice of daily, weekly or monthly data. function init(status) { if (status == Loading || status == Editing) { dataSource = storage.getAt(0); } if (status == Adding || status == Editing) { var dlg = new Dialog("Choose Data Type", 170, 40); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("dataSource",45,-1,50,-1,dataList, "Data Source","",dataSource); if (dlg.show() == Dialog.Ok) { dataSource=dlg.getValue("dataSource") storage.setAt(0, dataSource); } else { return false; } } setTitle("Impulse System ("+macdShort+","+macdLong+","+macdSignal+" MACD & "+maPeriods+" EMA "+dataList[dataSource]+")"); } function getVal(share) { if (dataSource == 0) var data = share.getPriceArray(); if (dataSource == 1) var data = share.getWeeklyBarArray(); if (dataSource == 2) var data = share.getMonthlyBarArray(); var ma1 = new MA(macdLong, MA.Exponential); var ma2 = new MA(macdShort, MA.Exponential); var ma3 = new MA(macdSignal, MA.Exponential); var ma4 = new MA(maPeriods, MA.Exponential); var main = new Array(); var signal = new Array(); var hist = new Array(); var ema = new Array(); hist[0] = ema[0] = 0; var output = 0; for (var i=1; ihist[i-1] && ema[i]>ema[i-1]) { if (output>=0) output++; else output = 1; } else if (hist[i]