CutomIndicatorPackageInJfx.java

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



// Copyright (c) 2009 Dukascopy (Suisse) SA. All Rights Reserved.
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;

// context.getFilesDir(通常は、〜Strategies/files)フォルダにあるjfxファイル名を指定するか、フルファイルパスを指定する
@CustomIndicators("Indicator.jfx")


// このストラテジーは、コンパイル済みの他ストラテジーファイル(.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();
        
        // for multiple indicators split the path with File.pathSeparator 
        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();
        
        // シフト1設定でインジケータ算出
        Object[] resultByShift =  indicators.calculateIndicator(
                                                feedDescriptor,
                                                new  OfferSide[] {OfferSide.BID},
                                                indName,
                                                new AppliedPrice[]{CLOSE},
                                                new Object[]{timePeriod},
                                                1
                                               );

        double prevValue = (Double) resultByShift[0];
        
        // バーインターバルで直近5本のインジケータを算出
        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 {}
}



このストラテジーは、Indicator.jfx内にあるインジケータを利用するので、
Strategies/filesフォルダにIndicator.jfxファイルを置く必要があります。
Indicator.jfxはIndicator.javaファイルをコンパイルして生成します。

またチャートを表示した状態でストラテジーを起動させる必要があります。



スポンサーリンク

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


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


Top

inserted by FC2 system