RectangleMoveByTick.java

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



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

import com.dukascopy.api.*;
import com.dukascopy.api.drawings.*;

/**
 ストラテジー起動時に四角形オブジェクトを作成し、
 ティック受信毎にオブジェクトを直近ティックデータ(時間とプライス)の位置に移動します。
 */
@RequiresFullAccess
public class RectangleMoveByTick implements IStrategy {

    private IChart chart;
    private IHistory history;
    private IRectangleChartObject rectangle;
    private Instrument instrument = Instrument.EURUSD;
    
    @Override
    public void onStart(IContext context) throws JFException {
        this.chart   = context.getChart(instrument);
        this.history = context.getHistory();
        ITick tick    = history.getLastTick(instrument);    
        
        long   barWidth = chart.getSelectedPeriod().getInterval();
        double tenPips  = instrument.getPipValue() * 10;

        rectangle = chart.getChartObjectFactory().createRectangle(
                        "rectangle", 
                        tick.getTime(),
                        tick.getBid(), 
                        tick.getTime() - barWidth * 10,
                        tick.getBid()  - tenPips
                    );

        chart.addToMainChart(rectangle);
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {  
        if(instrument != this.instrument){
            return;
        }
        rectangle.move(tick.getTime(), tick.getBid());
    }

    @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 {
        chart.removeAll();
    }
}







スポンサーリンク

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


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


Top

inserted by FC2 system