//@Name:TSF and MA //@Description: Draws the Time Series Forecast of the Price and gives the option to draw an MA of the TSF. //@Enviroment: Production // 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 period1=20; var period2=20; var colour1=11862016; var colour2=255; var width1=0; var width2=0; var pen1=0; var pen2=0; var MAType = 0; var MAOption = 1; var MAList = ["Simple","Exponential","Weighted","Triangular","VariableVHF","VariableCMO","VIDYA","Hull","TEMA"]; var dataList = ["Open","High","Low","Close","Typical","Median","Weighted"]; var dataType = 3; var P12MO; var MATDT function init(status) { if (status == Loading || status == Editing) { MOP12 = storage.getAt(0); MATDT = storage.getAt(1); colour1 = storage.getAt(2); colour2 = storage.getAt(3); width1 = storage.getAt(4); width2 = storage.getAt(5); pen1 = storage.getAt(6); pen2 = storage.getAt(7); MOP12 = MOP12.toString(); MAOption=(parseInt(MOP12.substr(0,1),10))-1; period1=parseInt(MOP12.substr(1,3),10); period2=parseInt(MOP12.substr(4,3),10); MATDT = MATDT.toString(); MAType=(parseInt(MATDT.substr(0,1),10))-1; dataType=(parseInt(MATDT.substr(1,1),10)); } if (status == Adding || status == Editing) { var dlg = new Dialog("Time Series Forecast", 245, 80); dlg.addOkButton(); dlg.addCancelButton(); dlg.addGroupBox(5,5,175,30,"Indicator Properties"); dlg.addIntEdit("VAL1",45,17,-1,-1, "TSF Period","",period1,2,999); dlg.addColLinePicker("VAL2",140,17,-1,-1,"","",colour1,pen1,width1); dlg.addDropList("VAL7",80,17,40,-1,dataList,"","",dataType); dlg.addGroupBox(5,45,175,30,""); dlg.addTickBox("VAL3",10,45,100,-1,"Moving Average Properties",MAOption); dlg.addIntEdit("VAL4", 45,57, -1, -1, "MA Period","",period2,2,999); dlg.addDropList("VAL5", 80, 57, 55, -1,MAList, "","",MAType); dlg.addColLinePicker("VAL6",140,57,-1,-1,"","",colour2,pen2,width2); if (dlg.show() == Dialog.Cancel) return false; period1 = dlg.getValue("VAL1"); period2 = dlg.getValue("VAL4"); MAOption = dlg.getValue("VAL3"); MAType = dlg.getValue("VAL5"); dataType = dlg.getValue("VAL7"); colour1=dlg.getValue("VAL2").colour; width1=dlg.getValue("VAL2").width; pen1=dlg.getValue("VAL2").pen; colour2=dlg.getValue("VAL6").colour; width2=dlg.getValue("VAL6").width; pen2=dlg.getValue("VAL6").pen; MOP12= (MAOption+1)*1000000+period1*1000+period2; MATDT= (MAType+1)*10+dataType; storage.setAt(0, MOP12); storage.setAt(1, MATDT); storage.setAt(2, colour1); storage.setAt(3, colour2); storage.setAt(4, width1); storage.setAt(5, width2); storage.setAt(6, pen1); storage.setAt(7, pen2); } //setTitle("Commodity Channel Index (CCI) "+period+" + Time Series Forecast "+tsf); setSeriesColour(0, colour1); setSeriesLineStyle(0, pen1, width1); setSeriesColour(1, colour2); setSeriesLineStyle(1, pen2, width2); } function getGraph(share, data) { var TSFMain = new Array(); var MAres = new Array(); var TSF1 = new Trend(period1); if(MAOption==1) { if (MAType == 8) { var sqrtperiod1 = Math.round(Math.sqrt(period2)); var ma1 = new MA(period2/2, MA.Weighted); var ma2 = new MA(period2, MA.Weighted); var ma3 = new MA(sqrtperiod1, MA.Weighted); for (var i=0; i