/***************************************************Provided By : eSignal. (c) Copyright 2003***************************************************/function preMain() {setStudyTitle("Nasdaq Volume");setCursorLabelName("Nasdaq Vol", 0);setCursorLabelName("Avg. Vol", 1);setPlotType(PLOTTYPE_HISTOGRAM,0);setDefaultBarThickness(3);setDefaultBarFgColor(Color.blue, 0);setPlotType(PLOTTYPE_LINE, 1);setDefaultBarFgColor(Color.purple, 1);}var vArray = new Array();var vInterval = getInterval();function main(nLength) {if (nLength == null) { nLength = 50;} else { nLength = Math.round(nLength);}if (vInterval == "D" || vInterval == "W" || vInterval == "M") { var vValue = close("$TVOLQ");} else { var c = close("$TVOLQ"); var o = open("$TVOLQ"); if (c == null || o == null) return; var vValue = c - o;}var nBarState = getBarState(); if (nBarState == BARSTATE_NEWBAR) { vArray.unshift(vValue); //inserts array element to the front of the array } else { vArray[0] = vValue;}if (vArray[nLength-1] != null) { // check to make sure array is full var vSum = 0; for(i = 0; i < nLength; i++) { vSum += vArray[i]; } var vAvgVol = vSum / nLength;} else { return;}if (vArray.length > nLength) vArray.pop(); // Removes last array itemreturn new Array(vValue, vAvgVol);} |