//@Name:TRIX Value //@Description:Returns the latest value or change of the TRIX indicator or its signal //@Returns:Number //@Width:90 //@Env:Production //@Update:Periodic,60 // 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 period=26 var sigPeriod=9 var outputList = ["TRIX","TRIX Signal","TRIX Change","TRIX Signal Change"]; var outputType = 0; var periodsAgo = 0; var lookback = 10; var dataList = ["Daily","Weekly","Monthly"]; var titleDataList = ["Td","Wk","Mnth"]; var dataSource = 0; var useIntra = 0; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); sigPeriod = storage.getAt(1); dataSource = storage.getAt(2); outputType = storage.getAt(3); lookback = storage.getAt(4); useIntra = storage.getAt(5); periodsAgo = storage.getAt(6); } if (status == Adding || status == Editing) { var dlg = new Dialog("Enter Value", 220, 135); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1", 65, -1, -1, -1, "Period", "",period,2,5000); dlg.addIntEdit("INT2", 65, -1, -1, -1, "Signal", "",sigPeriod,3,5000); dlg.addDropList("DL1",65,-1,70,-1, dataList,"","",dataSource); dlg.addDropList("DL2",65,-1,70,-1, outputList, "Output","",outputType); dlg.addIntEdit("INT4", 65, -1, -1, -1, "Show value", "periods ago",periodsAgo,0,1000); dlg.addIntEdit("INT3", 65, -1, -1, -1, "Change over ", "periods",lookback,1,1000); dlg.addTickBox("TB1",10,-1,195,-1,"Include latest intraday price", useIntra); if (dlg.show() == Dialog.Cancel) return false; period=dlg.getValue("INT1"); sigPeriod=dlg.getValue("INT2"); dataSource=dlg.getValue("DL1"); outputType=dlg.getValue("DL2"); lookback=dlg.getValue("INT3"); useIntra=dlg.getValue("TB1"); periodsAgo=dlg.getValue("INT4"); storage.setAt(0, period); storage.setAt(1, sigPeriod); storage.setAt(2, dataSource); storage.setAt(3, outputType); storage.setAt(4, lookback); storage.setAt(5, useIntra); storage.setAt(6, periodsAgo); } if (outputType<2) { setTitle(period+", "+sigPeriod+" "+outputList[outputType]+" ("+periodsAgo+" "+titleDataList[dataSource]+(periodsAgo==1?"":"s")+" ago)"); } else { setTitle(period+", "+sigPeriod+" "+outputList[outputType]+" ("+lookback+" - "+periodsAgo+" "+titleDataList[dataSource]+(periodsAgo==1?"":"s")+" ago)"); } } function getVal(share) { data = getData(share,dataSource,useIntra) if (data.length<2 || (outputType>1 && lookback+periodsAgo>=data.length) || periodsAgo>=data.length) return; var ma1 = new MA(period, MA.Exponential); var ma2 = new MA(period, MA.Exponential); var ma3 = new MA(period, MA.Exponential); var ma4 = new MA(sigPeriod, MA.Exponential); var smoothing = new Array(); var trix = new Array(); var signal = new Array(); smoothing[0] = data[0].close; trix[0] = signal[0] = 0; for (i=1;idata[data.length-1].high?idata[0].high:data[data.length-1].high), low:(idata[0].lowdata[data.length-1].high?idata[0].high:data[data.length-1].high), low:(idata[0].low