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.

Different behavior during execution and testing
 Post subject: Different behavior during execution and testing Post rating: 0   New post Posted: Thu 25 Jun, 2015, 17:21 

User rating: 0
Joined: Thu 12 Dec, 2013, 09:24
Posts: 21
Location: Ukraine, Kyiv
I have the following need, I need to get current ema value during execution. In order to do this I created following code:

package jforex.strategies.indicators.test2;
import com.dukascopy.api.Filter;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import com.dukascopy.api.Unit;

public class EmaAtomicTests implements IStrategy {

private IConsole console;
private IHistory history;
private IIndicators indicators;
public Period period3Min = Period.createCustomPeriod(Unit.Minute, 3);

@Override
public void onStart(IContext context) throws JFException {
period3Min = Period.createCustomPeriod(Unit.Minute, 3);
console = context.getConsole();
history = context.getHistory();
indicators = context.getIndicators();
context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
}

private void testShift() throws JFException {
int shift = 0;
double ema = indicators.ema(Instrument.EURUSD, period3Min , OfferSide.ASK, AppliedPrice.CLOSE, 6, shift);
console.getOut().format("last bar ema=%.5f", ema).println();
}

private void testTimeInterval() throws JFException {
long from = history.getBar(Instrument.EURUSD, period3Min, OfferSide.BID, 12).getTime();
long to = history.getBar(Instrument.EURUSD, period3Min, OfferSide.BID, 0).getTime();

double[] ema = indicators.ema(Instrument.EURUSD, period3Min, OfferSide.BID, AppliedPrice.CLOSE, 6, from, to);
int last = ema.length - 1;
console.getOut().format("Current bar ema=%.5f; Previous bar ema=%.5f; Third to last bar ema=%.5f",
ema[last], ema[last - 1], ema[0]).println();
}

@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
testTimeInterval();
}

@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}

@Override
public void onMessage(IMessage message) throws JFException {}

@Override
public void onAccount(IAccount account) throws JFException {}

@Override
public void onStop() throws JFException {}

}

As outcome I have following situation: during executing of platform I have all values displayed correctly. For example ema6 is printed correctly. But if I execute in Historical tester mode I see following error message:

2015-06-25 16:13:17 Strategy tester: java.lang.NullPointerException @ jforex.strategies.indicators.test2.EmaAtomicTests.testTimeInterval(EmaAtomicTests.java:43)
does anybody knows how to fix this?


Attachments:
EmaAtomicTests.java [2.48 KiB]
Downloaded 58 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Different behavior during execution and testing Post rating: 0   New post Posted: Thu 02 Jul, 2015, 15:00 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We will investigate this and get back to you as soon as possible.


 
 Post subject: Re: Different behavior during execution and testing Post rating: 0   New post Posted: Tue 07 Jul, 2015, 12:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Greetings.

3min periods are not default periods. You need to subscribe to that feed.
E.g. use some of the IContext methods:

<T extends ITimedData> void subscribeToFeed(ITailoredFeedDescriptor<T> feedDescriptor, ITailoredFeedListener<T> feedListener);
void subscribeToFeed(IFeedDescriptor feedDescriptor, IFeedListener feedListener);

By default, when we subscribe an instrument, we subscribe to such feed:

result.add(Period.TICK);
result.add(Period.TEN_SECS);
result.add(Period.ONE_MIN);
result.add(Period.FIVE_MINS);
result.add(Period.TEN_MINS);
result.add(Period.FIFTEEN_MINS);
result.add(Period.THIRTY_MINS);
result.add(Period.ONE_HOUR);
result.add(Period.FOUR_HOURS);
result.add(Period.DAILY);
result.add(Period.WEEKLY);
result.add(Period.MONTHLY);

Best regards, Support Team.


 

Jump to:  

cron
  © 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