I downloaded the program called "BidAskVolume" and ran it. It will only give me the total volume and not the bid or ask volume. I narrowed it down to the statement that is causing the problem:
if (getCurrentBarIndex() < 0) return;
it appears that getCurrentBarIndex is never 0, it is always -1. What am I doing wrong?
The program is below:
if (getCurrentBarIndex() < 0) return;
it appears that getCurrentBarIndex is never 0, it is always -1. What am I doing wrong?
The program is below:
PHP Code:
function preMain() {
setStudyTitle("Bid\/Ask Volume ");
setCursorLabelName("Ask Vol", 0);
setCursorLabelName("Inside Vol", 1);
setCursorLabelName("Bid Vol", 2);
setDefaultBarFgColor(Color.green, 0);
setDefaultBarFgColor(Color.black, 1);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarThickness(4, 0);
setDefaultBarThickness(6, 1);
setDefaultBarThickness(4, 2);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
setPlotType(PLOTTYPE_HISTOGRAM, 1);
setPlotType(PLOTTYPE_HISTOGRAM, 2);
var fp0 = new FunctionParameter("sType", FunctionParameter.STRING);
fp0.setName("Analysis");
fp0.addOption("Bar");
fp0.addOption("Cumulative");
fp0.setDefault("Bar");
}
var nBidVol = 0;
var nInsideVol = 0;
var nAskVol = 0;
var vVol = null;
var bPrimed = false;
var nAsk = null;
var nBid = null;
function main(sType) {
if (getCurrentBarIndex() < -1) return; // ****** This is where the problem is? ******
var nState = getBarState();
if (nState == BARSTATE_NEWBAR) {
if (sType == "Bar" || day(0) != day(-1)) {
nBidVol = 0;
nInsideVol = 0;
nAskVol = 0;
}
vVol = 0;
}
var vPrevVol = null;
if (vVol != null && bPrimed == true) vPrevVol = vVol;
var nTempAsk = getMostRecentAsk();
var nTempBid = getMostRecentBid();
if (nTempAsk != null && nTempAsk != 0) nAsk = nTempAsk;
if (nTempBid != null && nTempBid != 0) nBid = nTempBid;
var vClose = close();
vVol = volume();
var vTradeVol = vVol - vPrevVol;
if (bPrimed == false && vVol != null) {
bPrimed = true;
return;
} else {
if (vClose <= nBid) {
nBidVol += vTradeVol;
} else if (vClose >= nAsk) {
nAskVol += vTradeVol;
} else {
nInsideVol += vTradeVol;
}
}
return new Array(nAskVol, nInsideVol, nBidVol);
}