//@LibraryID:1064,0 //@Name:Force Index Value //@Description:Returns the latest value of the Force Index Indicator // In 'Trading for a Living' there are many comments, extensions and extra rules and considerations // 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 ma = 2; var maType = 1; var maTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA"]; var maList = ["Simple","Exponential","Weighted","Triangular","VariableVHF","VariableCMO","VIDYA"]; function init(status) { if (status == Loading || status == Editing) { ma = storage.getAt(0); maType = storage.getAt(1); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings",220,45); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("VAL1",80,6,-1,-1,maList,"","",maType); dlg.addIntEdit("VAL2",40,6,-1,-1,"MA period","",ma,2,999); if (dlg.show()==Dialog.Cancel) return false; maType = dlg.getValue("VAL1"); ma = dlg.getValue("VAL2"); storage.setAt(0, ma); storage.setAt(1, maType); } setTitle("Force Index Value (m) "+"("+ma+maTitleList[maType]+")"); } function getVal(share) { var data = getData(share); if (data == undefined || data.length < 2) return; var output = new Array(); var max = 0; output[0]=undefined; var ema = new MA(ma, maType); for (var i=1; imax) max=output[i]; if (output[i]< -max) max= -output[i]; } return output[output.length-1]/max; } function getData(share) { var data = share.getPriceArray(); if (data.length<2) return; return data; }