package jforex.logging;
import java.util.Arrays;
import java.util.List;
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.IIndicators.MaType;
import com.dukascopy.api.util.DateUtils;
public class LoggingValues implements IStrategy {
private IConsole console;
private IHistory history;
private IIndicators indicators;
@Override
public void onStart(IContext context) throws JFException {
console = context.getConsole();
history = context.getHistory();
indicators = context.getIndicators();
IBar prevBar = history.getBar(
Instrument.EURUSD,
Period.TEN_SECS,
OfferSide.BID,
1
);
long time = prevBar.getTime();
double max = indicators.max(
Instrument.EURUSD,
Period.TEN_SECS,
OfferSide.BID,
AppliedPrice.CLOSE,
20,
1
);
console.getOut().format("単一の値(maxインジケータの結果): %.5f 直前のバー時間=%s 直前のバー情報=%s",
max,
DateUtils.format(time),
prevBar
).println();
double[][] bbands = indicators.bbands(
Instrument.EURUSD,
Period.TEN_SECS,
OfferSide.BID,
AppliedPrice.CLOSE,
20,
5,
4,
MaType.SMA,
Filter.NO_FILTER,
5,
time,
0
);
print("2次元配列のログ出力(ボリンジャーバンドインジケータ算出結果): " + arrayToString(bbands) );
double[] maxArr = indicators.max(
Instrument.EURUSD,
Period.TEN_SECS,
OfferSide.BID,
AppliedPrice.CLOSE,
20,
Filter.NO_FILTER,
5,
time,
0
);
print("1次元配列のログ出力(maxインジケータ算出結果): " + arrayToString(maxArr));
List<IBar> bars = history.getBars(
Instrument.EURUSD,
Period.TEN_SECS,
OfferSide.BID,
Filter.NO_FILTER,
5,
time,
0
);
console.getOut().format("―――\n" +
"オブジェクト配列(バー履歴取得結果)\n" +
"インデックス配列 : %s \n" +
"非インデックス配列: %s\n" +
"リスト : %s",
arrayToString(bars.toArray()),
Arrays.toString(bars.toArray()),
bars
).println();
context.stop();
}
private void print(Object o){
console.getOut().println(o);
}
public static String arrayToString(double[] arr) {
StringBuilder sb = new StringBuilder();
for (int r = 0; r < arr.length; r++) {
sb.append(String.format("[%s] %.5f; ",r, arr[r]));
}
return sb.toString();
}
public static String arrayToString(Object[] arr) {
StringBuilder sb = new StringBuilder();
for (int r = 0; r < arr.length; r++) {
sb.append(String.format("[%s] %s; ",r, arr[r]));
}
return sb.toString();
}
public static String arrayToString(double[][] arr) {
StringBuilder sb = new StringBuilder();
for (int r = 0; r < arr.length; r++) {
for (int c = 0; c < arr[r].length; c++) {
sb.append(String.format("[%s][%s] %.5f; ",r, c, arr[r][c]));
}
sb.append("; ");
}
return sb.toString();
}
@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 {}
}