|
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.
NullPointerException |
[thomey]
|
Post subject: NullPointerException |
Post rating: 0
|
Posted: Mon 13 Dec, 2010, 16:15
|
|
User rating: 0
Joined: Mon 11 Oct, 2010, 13:42 Posts: 8
|
Hello, Since the weekend I get a Null Pointer Exeption when a condition is fulfilled. I don't see a reason for this, as everything worked before. I'm using a custom indicator ( nearly the same as the DMI). This is the code in onBar(): public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (instrument.equals(currentInstrument)) { ask = askBar.getClose(); bid = bidBar.getClose(); orderList = engine.getOrders(currentInstrument); try { if (positionsTotal(instrument) < positionsAmount) { // Indikator Integer[] optParams = new Integer[1]; optParams[0] = 21; Object[] dmiNext = indicators.calculateIndicator(currentInstrument, indiPeriod, new OfferSide[]{OfferSide.BID}, "DMICustom", new IIndicators.AppliedPrice[]{IIndicators.AppliedPrice.TYPICAL_PRICE}, optParams, 0); Object[] dmi = indicators.calculateIndicator(currentInstrument, indiPeriod, new OfferSide[]{OfferSide.BID}, "DMICustom", new IIndicators.AppliedPrice[]{IIndicators.AppliedPrice.TYPICAL_PRICE}, optParams, 1); Object[] dmiPrev = indicators.calculateIndicator(currentInstrument, indiPeriod, new OfferSide[]{OfferSide.BID}, "DMICustom", new IIndicators.AppliedPrice[]{IIndicators.AppliedPrice.TYPICAL_PRICE}, optParams, 2);
double adx = (Double) dmi[0]; double dmiPlus = (Double) dmi[1]; double dmiMinus = (Double) dmi[2];
double adxPrev = (Double) dmiPrev[0]; double dmiPlusPrev = (Double) dmiPrev[1]; double dmiMinusPrev = (Double) dmiPrev[2];
double adxNext = (Double) dmiNext[0]; double dmiPlusNext = (Double) dmiNext[1]; double dmiMinusNext = (Double) dmiNext[2];
if (dmiPlusPrev < dmiMinusPrev && dmiPlus > dmiMinus && dmiPlusNext > dmiMinusNext) { console.getOut().print(" Crossed "); //This is line 194 (...) Error message: Quote: 15:03:05 Strategy tester: java.lang.NullPointerException @ com.dukascopy.jforex.DMIScalper.onBar(DMIScalper.java:194) - Tested on Historical Tester - Platform cache and Java cache were cleaned before testing I already searched for the reason, but I can't figure it out. Thanks for any suggestions
|
|
|
|
 |
[thomey]
|
Post subject: Re: NullPointerException |
Post rating: 0
|
Posted: Tue 14 Dec, 2010, 12:14
|
|
User rating: 0
Joined: Mon 11 Oct, 2010, 13:42 Posts: 8
|
I tried to filter out the bars and call a different indicator. Object[] values = indicators.calculateIndicator(Instrument.EURUSD, Period.ONE_HOUR, new OfferSide[] {OfferSide.ASK}, "DMI", new AppliedPrice[] {}, new Object[]{14}, shift); console.getOut().println("adx: " + ((Object[])values)[0] + ", +di: " + ((Object[])values)[1] + ", -di: " + ((Object[])values)[2]); Now the only code in onBar is the following: public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (!instrument.equals(Instrument.EURUSD) || !period.equals(Period.FIVE_MINS)) return; { ask = askBar.getClose(); bid = bidBar.getClose(); orderList = engine.getOrders(currentInstrument); try { if (positionsTotal(instrument) < positionsAmount) { Object[] values = indicators.calculateIndicator(Instrument.EURUSD, Period.FIVE_MINS, new OfferSide[] {OfferSide.BID}, "DMI", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, new Object[]{14}, 1); console.getOut().println("adx: " + ((Object[])values)[0] + ", +di: " + ((Object[])values)[1] + ", -di: " + ((Object[])values)[2]); } else if ((positionsTotal(instrument) > 0)) { // no instructions here }
} catch (JFException ex) { ex.printStackTrace(); System.out.println("Error : " + ex); } catch (java.lang.ArrayIndexOutOfBoundsException e) { e.printStackTrace(); System.out.println("Error : " + e); } }
} I still get the same error "2010-12-14 11:08:51 Strategy tester: java.lang.NullPointerException @ com.dukascopy.jforex.DMIScalper.onBar(DMIScalper.java:251)" with line 251 being the print instruction. What could be the origin of this error?
|
|
|
|
 |
API Support
|
Post subject: Re: NullPointerException |
Post rating: 0
|
Posted: Mon 27 Dec, 2010, 08:55
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, DMI indicator has three outputs whereas ADX indicator has only one output. Please have a look at the following code: double[] dmi = indicators.dmi(instrument, period, OfferSide.ASK, 12, shift); console.getOut().println("adx: " + dmi[0] + ", +di: " + dmi[1] + ", -di: " + dmi[2]); long prevBarTime = history.getBar(instrument, period, OfferSide.ASK, shift).getTime(); double[][] fromToDmi = indicators.dmi(instrument, period, OfferSide.ASK, 12, prevBarTime, prevBarTime); console.getOut().println("adx: " + fromToDmi[0][0] + ", +di: " + fromToDmi[1][0] + ", -di: " + fromToDmi[2][0]); int candlesBefore = 1, candlesAfter = 0; double[][] filteredDmi = indicators.dmi(instrument, period, OfferSide.ASK, 12, Filter.NO_FILTER, candlesBefore, prevBarTime, candlesAfter); console.getOut().println("adx: " + filteredDmi[0][0] + ", +di: " + filteredDmi[1][0] + ", -di: " + filteredDmi[2][0]); Object[] universalDmi = indicators.calculateIndicator(instrument, period, new OfferSide[] {OfferSide.ASK}, "DMI", new AppliedPrice[] {}, new Object[]{12}, Filter.NO_FILTER, 1, prevBarTime, 0); console.getOut().println("adx: " + ((double[])universalDmi[0])[0] + ", +di: " + ((double[])universalDmi[1])[0] + ", -di: " + ((double[])universalDmi[2])[0]);
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|