For running your strategy from JForex client, see:
https://www.dukascopy.com/wiki/index.php ... de_on_newsFor running your strategy from API, consider the following filter:
NewsFilter newsFilter = new NewsFilter();
newsFilter.setTimeFrame(NewsFilter.TimeFrame.TODAY);
newsFilter.getKeywords().add("MARKET TALK");
client.addNewsFilter(newsFilter);
CalendarFilter calendarFilter = new CalendarFilter();
calendarFilter.setTimeFrame(NewsFilter.TimeFrame.TODAY);
client.addNewsFilter(calendarFilter);
//start the strategy
LOGGER.info("Starting strategy");
client.startStrategy(new NewsStrategyNoTrades());
Consider using either the strategy from the above wiki link or the following strategy which just prints the news' messages:
package jforex.news;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import com.dukascopy.api.*;
public class NewsStrategyNoTrades implements IStrategy {
private IConsole console;
@SuppressWarnings("serial")
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {{setTimeZone(TimeZone.getTimeZone("GMT"));}};
public void onStart(IContext context) throws JFException {
this.console = context.getConsole();
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
if (message.getType().equals(IMessage.Type.CALENDAR)) {
print("CALENDAR MESSAGE: " + ((ICalendarMessage) message).getAction() + " " + sdf.format(((ICalendarMessage) message).getEventDate()) + " " + ((ICalendarMessage) message).getCountry());
} else if (message.getType().equals(IMessage.Type.NEWS)){
print("NEWS MESSAGE: " + ((INewsMessage) message).getHeader() + " " + ((INewsMessage) message).getMarketSectors());
}
}
public void onStop() throws JFException { }
public void onTick(Instrument instrument, ITick tick) throws JFException { }
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { }
private void print(Object o){
console.getErr().println(o);
}
}
Note that
news feed works only with live data - you can't receive news in your strategy while working with historical data.