Objectives ...
1) Display a positive histogram of volume
2) Display a histogram in the negative of which volume is greater (buy or sell)
3) Display a Simple Moving Average (SMA) of the total volume as listed in 1) as a line
4) Display 2 Standard Deviations of the SMA as a line
what am i doing wrong ....
outputs[0][] is the histogram of total volume
outputs[1][] is the SMA
outputs[2][] is the StDv
outputs[3][] is the histogram of Bearish Volume
outputs[4][] is the histogram of Bullish Volume
desired lookback is 20 but am using a variable to make the indicator more flexible ..
public IndicatorResult calculate(int startIndex, int endIndex)
{
//calculating startIndex taking into account lookback value
if(startIndex - getLookback() < 0)
{
startIndex -= startIndex - getLookback();
}
if(startIndex > endIndex)
{
return new IndicatorResult(0,0);
}
int aOutLen = endIndex - startIndex + 1;
double aVolBid, aVolAsk;
for(int i=0;i<aOutLen;i++)
{
//boolean aWrongBTime = !((iBidBars.length == iAskBars.length) && (iBidBars[startIndex+i].getTime() == iAskBars[startIndex+i].getTime()) );
//aVolBid = iBidBars[startIndex+i].getVolume(); // Vol. of [B] UYERS / Investor SELLS and Market BUYS
//aVolAsk = iAskBars[startIndex+i].getVolume(); // Vol. of [S] ELLERS / Investor BUYS and market SELLS
// PART 1) Display combined volume and use a negative histogram to denote more or less buy/sell volume in a give period/bar
// PART 2) Calculate and display a simple moving average of the combined volume as well as 2 Standard Deviations above that average
double aTempVal = 0,
aTempVal2 = 0;
for (int x=0; x <= (aLookback-1); x++)
{
// error is given for line below exception 104
aTempVal += (iBidBars[startIndex+(i+x)].getVolume()+iAskBars[startIndex+(i+x)].getVolume());
// error is given for line above exception 104
if ((i==0) && (x==0) && (aTempVal>0))
{
outputs[0][i]=aTempVal;
if((100*(iAskBars[startIndex+(i+x)].getVolume()/(aTempVal))) >= 50)
{
outputs[3][i] = -1000; // Vol. Ask/Sell force
outputs[4][i] = 0;
}
else
{
outputs[3][i] = 0;
outputs[4][i] = -1000; // Vol. Bid/Buy force
}
}
}
outputs[1][i] = aTempVal;
for (int xx=0; xx <= (aLookback-1); xx++)
{
aTempVal2 += Math.pow((iBidBars[startIndex+(i+xx)].getVolume()+iAskBars[startIndex+(i+xx)].getVolume() - aTempVal),2);
}
outputs[2][i] = Math.sqrt((aTempVal2/aLookback));
}
return new IndicatorResult(startIndex,aOutLen);
}