Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Error Message - "cannot invoke com.dukascopy.api.IBar getHigh()" because "Bar" is null
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=21&t=58128
Page 1 of 1

Author:  us_copiosus [ Tue 18 Oct, 2022, 21:39 ]
Post subject:  Error Message - "cannot invoke com.dukascopy.api.IBar getHigh()" because "Bar" is null

Hi
I have the following code which causes the above error message from time to time:-

Any suggestions on recoding to remove error message

Bob M

public int getPipsAverage(long time, int numPer) {
            try {
                IHistory history = context.getHistory();
                //
                long firstBarTime = history.getPreviousBarStart(mPeriod, time);                   
                List<IBar> bars   = history.getBars(instrument, mPeriod, OfferSide.BID, history.getTimeForNBarsBack(mPeriod, firstBarTime, numPer), firstBarTime);
                //
                int  diff  = 0;
                int  count = 0;
                for (IBar bar: bars) {                   
                    double high  = bar.getHigh();
                    double low   = bar.getLow();                       
                    int    range = (int)Math.round(numberOfPips(high,  low));
                    if (range > 0) {
                        diff  = diff + range;
                        count = count + 1;
                    }                   
                }
                return diff / count;       
                //
            } catch (JFException e) {
                logger.error(e.getMessage());
                return -1;
            }
        } // end getPipsAverage

  Page 1 of 1