Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Help Please with Excetion 104
 Post subject: Help Please with Excetion 104 Post rating: 0   New post Posted: Wed 08 Jun, 2011, 06:28 

User rating: 0
Joined: Thu 26 May, 2011, 15:14
Posts: 1
Location: US
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);
    }


 
 Post subject: Re: Help Please with Excetion 104 Post rating: 0   New post Posted: Wed 08 Jun, 2011, 15:15 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please have a look at the following code:
        ...
        double aTempVal = 0;
        for (int i = startIndex, j = 0; i <= endIndex; i++, j++){
           //sum of Ask volume and Bid volume for the last (i - aLookback) bars
           for (int x = 0; x <= aLookback; x++){
              aTempVal += (inputs[1][i - x].getVolume() + inputs[0][i - x].getVolume());   
           }
           outputs[0][j] = aTempVal;
        }
        ...


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com