"actual IBar" is the current bar, which is displayed in the chart. But the API returns no value for this IBar!
You can proof this with the following program:
1. Open only one chart EURUSD in JForex
2. Set a custom period to 2 Minutes (via preferences)
3. Set the opened chart to 2 Minutes period
4. Compile and start the strategy CustomPeriodBarBug
5. View the messages, e.g.
12:22:13 EUR/USD, 2 Mins bar1 close = 1.34474
12:22:13 EUR/USD, 2 Mins bar0 close = null !
12:22:13 checking 2 Mins
bar1 has a value, bar0 (the actual) not!
Tested with
Dukascopy ver. 2.13.34
JForex API ver. 2.6.38.1
Java 6, 32 bit, Update 26
Win 7, 64 bit
/*
* This is a test program only, do not use for trading!
* It checks the JForex bar algorithm for the current Period of the first opened chart in JForex
* which is found by the getChart() function of the JForex API
*
* (c) 2011 Stash GmbH München
* www.stash.de
* Author: Bernhard Schicht
* [email protected]
*/
package jforex;
import java.util.*;
import com.dukascopy.api.*;
public class CustomPeriodBarBug implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public IChart currentChart = null;
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (instrument != Instrument.EURUSD) return;
String bar0Close = null;
String bar1Close = null;
if (context.getChart(instrument) != null) currentChart = context.getChart(instrument);
if (currentChart == null){
console.getOut().println("currentChart == null!");
return;
}
console.getOut().println("checking "+currentChart.getSelectedPeriod().toString());
IBar bar0 = getBar(instrument, currentChart.getSelectedPeriod(), 0);
if (bar0 == null) bar0Close = "null !";
else bar0Close = String.valueOf(bar0.getClose());
console.getOut().println(currentChart.toString()+" bar0 close = "+bar0Close);
IBar bar1 = getBar(instrument, currentChart.getSelectedPeriod(), 1);
if (bar1 == null) bar1Close = "null !";
else bar1Close = String.valueOf(bar1.getClose());
console.getOut().println(currentChart.toString()+" bar1 close = "+bar1Close);
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
public IBar getBar(Instrument instr, Period period, int barsBack){
try{
return history.getBar(instr, period, OfferSide.BID, barsBack);
}
catch (Exception e){
e.printStackTrace(console.getErr());
return null;
}
}
}