You can do it in this way:
package jforex;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
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;
public class IncreasePeriodStrategy implements IStrategy {
IContext context;
IConsole console;
IIndicators indicators;
Instrument myInstrument = Instrument.EURUSD;
Period myPeriod = Period.FOUR_HOURS;
@Override
public void onStart(IContext context) throws JFException {
this.context = context;
this.console = context.getConsole();
this.indicators = context.getIndicators();
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar)
throws JFException {
if (instrument != myInstrument || period != myPeriod) return;
Object[] thisIndicatorTSIOutput = indicators.calculateIndicator(myInstrument, myPeriod, new OfferSide[]{OfferSide.BID},
"TSI", new AppliedPrice[]{AppliedPrice.CLOSE}, new Object[]{20,13,7}, 0);
console.getOut().println("Period: " + myPeriod +" " + thisIndicatorTSIOutput[0] + " " + thisIndicatorTSIOutput[1] + " " + thisIndicatorTSIOutput[2]);
//Some logic to check indicator in next time frame
Period nextPeriod = getNextPeriod(myPeriod);
Object[] nextPeriodIndicatorTSIOutput = indicators.calculateIndicator(myInstrument, nextPeriod, new OfferSide[]{OfferSide.BID},
"TSI", new AppliedPrice[]{AppliedPrice.CLOSE}, new Object[]{20,13,7}, 0);
console.getOut().println("Period: " + nextPeriod + " " + nextPeriodIndicatorTSIOutput[0] + " " + nextPeriodIndicatorTSIOutput[1] + " " + nextPeriodIndicatorTSIOutput[2]);
}
@Override
public void onMessage(IMessage message) throws JFException {
}
@Override
public void onAccount(IAccount account) throws JFException {
}
@Override
public void onStop() throws JFException {
}
private Period getNextPeriod(Period period) {
Period[] periods = Period.values();
int index = period.ordinal();
int nextIndex = index + 1;
nextIndex %= periods.length;
return periods[nextIndex];
}
}