LogProfitLoss.java

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



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

import com.dukascopy.api.*;
import com.dukascopy.api.util.DateUtils;

/**
 ポジションの損益集計結果を指定したログ出力間隔の時間経過毎にログ出力します
*/

public class LogProfitLoss implements IStrategy {

    private IEngine engine;
    private IConsole console;
    
    @Configurable("通貨ペア")
    public Instrument printInstrument = Instrument.EURUSD;
    @Configurable("ログ出力間隔")
    public Period printPeriod = Period.TEN_SECS;
        
    @Override
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        context.setSubscribedInstruments(java.util.Collections.singleton(printInstrument), true);
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if(instrument != this.printInstrument || period != this.printPeriod)
            return;
        
        double profitLoss = 0;
        for (IOrder order : engine.getOrders()) {
            if (order.getState() == IOrder.State.FILLED){
                profitLoss += order.getProfitLossInUSD();
            }
        }
        console.getOut().format("%s 損益 = $%.5f ", DateUtils.format(askBar.getTime() + period.getInterval()),profitLoss).println();

    }
    public void onMessage(IMessage message) throws JFException {}
    public void onAccount(IAccount account) throws JFException {}
    public void onStop() throws JFException {}
}









スポンサーリンク

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


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


Top

inserted by FC2 system