SentimentIndexInterval.java

注意事項:
サンプルソースコードには実際にオーダーを発注するものがあります。
サンプルソースコードのストラテジーを起動する場合は、注意して下さい。



// Copyright (c) 2009 Dukascopy (Suisse) SA. All Rights Reserved.
package jforex.strategies.indicators.test;

import java.util.List;
import com.dukascopy.api.*;

/**
 * 対象の通貨ペアと、その通貨ペア基軸通貨と決済通貨のセンチメントインデックスアグリゲーションバーを取得します
 */
public class SentimentIndexInterval implements IStrategy {

    private IConsole console;
    private IHistory history;
    private IDataService dataService;

    @Configurable("時間軸")
    public Period period = Period.FOUR_HOURS;
    @Configurable("通貨ペア")
    public Instrument instr = Instrument.EURUSD;
    @Configurable("バーカウント")
    public int barCount = 3;

    @Override
    public void onStart(IContext context) throws JFException {
        console     = context.getConsole();
        history     = context.getHistory();
        dataService = context.getDataService();
        
        long lastTickTime = history.getTimeOfLastTick(instr);
        long from         = history.getTimeForNBarsBack(period, lastTickTime, barCount);
        long to           = history.getTimeForNBarsBack(period, lastTickTime, 1);

        // 単一バーを取得する場合は、toとfromを同じ値にします。
        printIndices(dataService.getFXSentimentIndex(instr                       , period, from, to), instr                       );
        printIndices(dataService.getFXSentimentIndex(instr.getPrimaryCurrency()  , period, from, to), instr.getPrimaryCurrency()  );
        printIndices(dataService.getFXSentimentIndex(instr.getSecondaryCurrency(), period, from, to), instr.getSecondaryCurrency());
    }
    
    private void printIndices(List<IFXSentimentIndexBar> sentimentBars, Object key){
        for (IFXSentimentIndexBar sentimentBar : sentimentBars) {
            console.getOut().println(key.toString() + " - " + sentimentBar + ", 終値: " + sentimentBar.getClose());
        }
    }

    @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 {}

}







スポンサーリンク

スポンサーリンク
検索
リファレンスツリー


Copyright ©2016 JForexAPIで自動売買させ隊! All Rights Reserved.


Top

inserted by FC2 system