package jforex.lib;
import java.util.Arrays;
import com.dukascopy.api.*;
import static com.dukascopy.api.IIndicators.AppliedPrice.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;
import com.dukascopy.api.indicators.IIndicator;
@CustomIndicators("Indicator.jfx")
public class CutomIndicatorPackageInJfx implements IStrategy {
private IConsole console;
private IIndicators indicators;
private IHistory history;
@Override
public void onStart(IContext context) throws JFException {
console = context.getConsole();
indicators = context.getIndicators();
history = context.getHistory();
String indPath = getClass().getAnnotation(CustomIndicators.class).value();
IIndicator indicator = indicators.getIndicatorByPath(indPath);
if( indicator == null ){
console.getErr().println( indPath + " パスのインジケータは登録されていません。");
context.stop();
}
String indName = indicator.getIndicatorInfo().getName();
IChart chart = context.getLastActiveChart();
if( chart != null ){
chart.add(indicator);
}
IFeedDescriptor feedDescriptor = chart != null
? chart.getFeedDescriptor()
: new TimePeriodAggregationFeedDescriptor(Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID, Filter.NO_FILTER);
int timePeriod = (Integer) indicator.getOptInputParameterInfo(0).getDescription().getOptInputDefaultValue();
Object[] resultByShift = indicators.calculateIndicator(
feedDescriptor,
new OfferSide[] {OfferSide.BID},
indName,
new AppliedPrice[]{CLOSE},
new Object[]{timePeriod},
1
);
double prevValue = (Double) resultByShift[0];
long lastTime = history.getFeedData(feedDescriptor, 0).getTime();
Object[] resultByCandleInterval = indicators.calculateIndicator(
feedDescriptor,
new OfferSide[] {OfferSide.BID},
indName,
new AppliedPrice[]{CLOSE},
new Object[]{timePeriod},
5,
lastTime,
0
);
double[] values = (double[]) resultByCandleInterval[0];
console.getOut().format("直前のバー=%.7f 直近5本=%s フィード=%s",
prevValue, Arrays.toString(values), feedDescriptor).println();
}
public void onTick(Instrument instrument, ITick tick) throws JFException {}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
public void onMessage(IMessage message) throws JFException {}
public void onAccount(IAccount account) throws JFException {}
public void onStop() throws JFException {}
}