/*********************************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: AVVersion: 1.0 09/25/2009 Formula Parameters: Default: Wide 2 Acc True Notes: **********************************/var fpArray = new Array();var bInit = false;function preMain(){ setPriceStudy(false); setShowCursorLabel(true); setShowTitleParameters(false); setStudyTitle("AV"); setCursorLabelName("M", 0); setPlotType(PLOTTYPE_LINE, 0); setDefaultBarFgColor(Color.blue, 0); setCursorLabelName("L", 1); setPlotType(PLOTTYPE_LINE, 1); setDefaultBarFgColor(Color.red, 1); setCursorLabelName("H", 2); setPlotType(PLOTTYPE_LINE, 2); setDefaultBarFgColor(Color.green, 2); var x = 0; fpArray[x] = new FunctionParameter("Wide", FunctionParameter.NUMBER); with(fpArray[x++]) { setLowerLimit(1); setDefault(2); } fpArray[x] = new FunctionParameter("Acc", FunctionParameter.BOOLEAN); with(fpArray[x++]) { setDefault("true"); } }var xAV1 = null;var xAV2 = null;var xAV3 = null;function main(Wide, Acc) {var nBarState = getBarState();var AI1 = 0;var AI2 = 0;var AI3 = 0;var BI1 = 0;var BI2 = 0;var BI3 = 0; if (nBarState == BARSTATE_ALLBARS) { if(Wide == null) Wide = 2; if(Acc == null) Acc = true; } if (bInit == false) { xAV1 = efsInternal("Calc_AV", Wide); xAV2 = getSeries(xAV1, 1); xAV3 = getSeries(xAV1, 2); bInit = true; } AI1 = xAV1.getValue(0); AI2 = xAV2.getValue(0); AI3 = xAV3.getValue(0); BI1 = xAV1.getValue(-Wide); BI2 = xAV2.getValue(-Wide); BI3 = xAV3.getValue(-Wide); if (Acc) { if (AI3 == null) return; return new Array(AI1, AI2, AI3); } else { if (BI3 == null) return; AI1 = (AI1 - BI1) / Wide; AI2 = (AI2 - BI2) / Wide; AI3 = (AI3 - BI3) / Wide; return new Array(AI1, AI2, AI3); } return;}var bSecondInit = false;var xHigh = null;var xLow = null;var xHmom = null;var xLmom = null;function Calc_AV(Wide) {var mp1 = 0;var mp2 = 0;var VI1 = 0;var VI2 = 0;var VI3 = 0; if (!bSecondInit) { xHigh = high(); xLow = low(); xHmom = mom(Wide, high()); xLmom = mom(Wide, low()); } if (xHmom.getValue(0) == null) return; mp1 = xHigh.getValue(0) - (xHigh.getValue(0) - xLow.getValue(0)) / 2; mp2 = xHigh.getValue(-Wide) - (xHigh.getValue(-Wide) - xLow.getValue(-Wide)) / 2; VI1 = (mp1 - mp2) * 100 / Wide; VI2 = xLmom.getValue(0) * 100 / Wide; VI3 = xHmom.getValue(0) * 100 / Wide; return new Array(VI1, VI2, VI3)} |