Dukascopy
 
 
Wiki JStore Search Login

Error Message - "cannot invoke com.dukascopy.api.IBar getHigh()" because "Bar" is null
 Post subject: Error Message - "cannot invoke com.dukascopy.api.IBar getHigh()" because "Bar" is null Post rating: 0   New post Posted: Tue 18 Oct, 2022, 21:39 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
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


 

Jump to:  

  © 1998-2024 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