Now I'm studying JForex API. Yesterday I faced with some troubles.
I made simple strategy based on crossing moving averages. I use ITesterClient.
I use onBar method to analyse market condition:
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (period != timeframe) return;
if (!shouldProcess(instrument)) return;
long time = history.getPreviousBarStart(period, askBar.getTime());
double[] fast = indicators.ma(instrument,
this.timeframe,
this.offerSide,
this.appliedPrice,
this.fast,
MaType.SMA,
this.maFilter,
2,
time,
0);
double[] slow = indicators.ma(instrument,
this.timeframe,
this.offerSide,
this.appliedPrice,
this.slow,
MaType.SMA,
this.maFilter,
2,
time,
0);
BigDecimal[] _fast = {new BigDecimal(fast[0], mathContext),
new BigDecimal(fast[1], mathContext)};
BigDecimal[] _slow = {new BigDecimal(slow[0], mathContext),
new BigDecimal(slow[1], mathContext)};
if (fast[0] > slow[0] && fast[1] < slow[1]) {
LOGGER.info(df.format(new Date(askBar.getTime())) + ": SELL. ");
LOGGER.info(df.format(new Date(time)) + ": "
+ "[2]= [" + _fast[1] + "]/[" + _slow[1] + "] "
+ "[1]= [" + _fast[0] + "]/[" + _slow[0] + "]");
closeLongOrders();
submitOrder(instrument, IEngine.OrderCommand.SELL, bidBar.getOpen(), "Sell");
}
if (fast[0] < slow[0] && fast[1] > slow[1]) {
LOGGER.info(df.format(new Date(askBar.getTime())) + ": BUY. ");
LOGGER.info(df.format(new Date(time)) + ": "
+ "[2]= [" + _fast[1] + "]/[" + _slow[1] + "] "
+ "[1]= [" + _fast[0] + "]/[" + _slow[0] + "]");
closeShortOrders();
submitOrder(instrument, IEngine.OrderCommand.BUY, askBar.getOpen(), "Buy");
}
}
the first troubleIf I start running from 1/01/2011 I've got next messages in the log:
24.10.2011 16:46:17 DEBUG Thread-5 Reading ticks from chunk file [/home/eugene/JForex/.cache/EURUSD/2011/01/27/22h_ticks.bi5] com.dukascopy.charts.data.datacache.CacheManager
24.10.2011 16:46:17 INFO StrategyRunner Thread 25.02.2011 22:00:00: BUY
24.10.2011 16:46:17 INFO StrategyRunner Thread 25.02.2011 21:45:00: [2]= [1.37514]/[1.37510] [1]= [1.37495]/[1.37511] 24.10.2011 16:46:17 DEBUG StrategyRunner Thread Exiting by timeout com.dukascopy.dds2.greed.agent.strategy.tester.StrategyRunner
24.10.2011 16:46:17 DEBUG StrategyRunner Thread Exiting by timeout com.dukascopy.dds2.greed.agent.strategy.tester.StrategyRunner
[there are a lot of the same messages. about 2 megabytes]
24.10.2011 16:46:17 INFO StrategyRunner Thread ORDER_SUBMIT_REJECTED: System offline
there system stop only after System.exit(1) had been added into submitOrder
private void submitOrder(Instrument instrument,
IEngine.OrderCommand orderCmd,
double price,
String label) throws JFException {
IOrder order = engine.submitOrder(label, instrument, orderCmd, amount, price, slippage);
IMessage message;
while (order.getState() == IOrder.State.CREATED || order.getState() == IOrder.State.OPENED) {
message = order.waitForUpdate(2, TimeUnit.SECONDS);
if (message != null) {
this.context.getConsole().getOut().println(message.getContent());
LOGGER.info(message.getType() + ": " + message.getContent());
if (message.getType() == IMessage.Type.ORDER_SUBMIT_REJECTED) System.exit(1);
}
}
}
And the second oneIf I start testing from 1/03/2011 The system gets the same values of MAs for two serial bars:
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 20:45:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:15:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
I can't understand how it can be
so I've got error message:
24.10.2011 16:31:36 ERROR StrategyRunner Thread Cannot create order with label that already exists
Could you explain me what are the causes of my troubles?