/*********************************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: Detrended Price Oscillator Version: 1.0 04/13/2009Formula Parameters: Default: Length 14 Source of Price CloseNotes: The Detrend Price Osc indicator is similar to a moving average, in that it filters out trends in prices to more easily identify cycles. The indicator is an attempt to define cycles in a trend by drawing a moving average as a horizontal straight line and placing prices along the line according to their relation to a moving average. It provides a means of identifying underlying cycles not apparent when the moving average is viewed within a price chart. Cycles of a longer duration than the Length (number of bars used to calculate the Detrend Price Osc) are effectively filtered or removed by the oscillator.**********************************/var fpArray = new Array();var bInit = false;function preMain() { setStudyTitle("Detrended Price Oscillator"); setCursorLabelName("Detrend Osc",0); setDefaultBarFgColor(Color.red,0); addBand(0, PS_SOLID, 1, Color.blue, 1); var x=0; fpArray[x] = new FunctionParameter("nLength", FunctionParameter.NUMBER); with(fpArray[x++]) { setName("Length"); setLowerLimit(1); setDefault(14); } fpArray[x] = new FunctionParameter("sPrice", FunctionParameter.STRING); with(fpArray[x++]){ setName("Source of Price"); addOption("open"); addOption("high"); addOption("low"); addOption("close"); addOption("hl2"); addOption("hlc3"); addOption("ohlc4"); setDefault("close"); } }var xDPO = null;function main(sPrice, nLength) {var nBarState = getBarState();var nResult = 0; if (nBarState == BARSTATE_ALLBARS) { if (sPrice == null) sPrice = "close"; if (nLength == null) nLength = 14; } if (bInit == false) { xDPO = efsInternal("Calc_DPO", nLength, sPrice); bInit = true; } nResult = xDPO.getValue(0); return nResult;}var xSMA = null;var xSource = null;var bSecondInit = false;function Calc_DPO(nLength, sPrice) {var nRes = 0 if (getCurrentBarCount() <= nLength) return; if (bSecondInit == false) { xSource = eval(sPrice)(); xSMA = sma(nLength, xSource); bSecondInit = true; } nRes = xSource.getValue(0) - xSMA.getValue(0); return nRes;} |