/*********************************Provided By: eSignal (Copyright c eSignal), a division of Interactive Data Corporation. 2009. All rights reserved. This sample eSignal Formula Script (EFS) is for educational purposes only and may be modified and saved under a new file name. eSignal is not responsible for the functionality once modified. eSignal reserves the right to modify and overwrite this EFS file with each new release.Description: Moving Trend (Rafter Indicator) Version: 1.0 05/19/2009 Formula Parameters: Default: N 20 Notes: The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.**********************************/var fpArray = new Array();var bInit = false;function preMain() { setStudyTitle("Movtrend"); setCursorLabelName("Movtrend", 0); setDefaultBarFgColor(Color.blue, 0); setPriceStudy(true); var x = 0; fpArray[x] = new FunctionParameter("n", FunctionParameter.NUMBER); with(fpArray[x++]) { setName("N"); setLowerLimit(1); setDefault(20); } }var xMovTrend = null;function main(n) {var nBarState = getBarState();var nMovTrend = 0; if (nBarState == BARSTATE_ALLBARS) { if(n == null) n = 20; } if (bInit == false) { xMovTrend = efsInternal("MovTrend", n); bInit = true; } nMovTrend = xMovTrend.getValue(0); if (nMovTrend == false) return; return nMovTrend; }var xClose = null;function MovTrend(n) {var nRes = 0;var sum = 0;var i = 0; if (xClose == null) xClose = close(); if (xClose.getValue(-n) == null) return; for(i = n; i > 0; i--) sum += (i - (n + 1) / 3) * xClose.getValue(i - n); nRes = 6 / (n * (n + 1)) * sum; return nRes;} |