rounder8 wrote:
The problem with this method is that if market has not been open throughout the time span then a JFException is thrown.
This is not the case (see in the example below).
rounder8 wrote:
Is there more elegant way to do this?
Consider application of candle stick filters, e.g.:
package jforex.strategies.indicators;
import java.util.Arrays;
import com.dukascopy.api.*;
@RequiresFullAccess
public class VolumeIndTest implements IStrategy {
private IIndicators indicators;
private IConsole console;
private IHistory history;
@Override
public void onStart(IContext context) throws JFException {
indicators = context.getIndicators();
console = context.getConsole();
history = context.getHistory();
long time = history.getBarStart(Period.FOUR_HOURS, history.getLastTick(Instrument.EURUSD).getTime());
double[] volumes = indicators.volume(Instrument.EURUSD, Period.FOUR_HOURS, OfferSide.BID, Filter.NO_FILTER, 50, time, 0);
double[] volumes2 = indicators.volume(Instrument.EURUSD, Period.FOUR_HOURS, OfferSide.BID, Filter.WEEKENDS, 50, time, 0);
//mind that the latest value is the last one in the array
console.getOut().println("volume no filter: " + Arrays.toString(volumes));
console.getOut().println("volume weekends filter: " + Arrays.toString(volumes2));
context.stop();
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {}
@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 {}
}