IndicatorPanelAddStochAndHLines.java

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



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

import java.awt.Color;

import com.dukascopy.api.*;
import com.dukascopy.api.drawings.IHorizontalLineChartObject;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.IndicatorInfo;
import com.dukascopy.api.indicators.OutputParameterInfo.DrawingStyle;

public class IndicatorPanelAddStochAndHLines implements IStrategy {

    @Configurable("通貨ペア")
    public  Instrument instrument = Instrument.EURUSD;
    private IChart      chart;
    private IConsole    console;
    private IIndicators indicators;

    @Override
    public void onStart(IContext context) throws JFException {
        this.chart      = context.getChart(instrument);
        this.console    = context.getConsole();
        this.indicators = context.getIndicators();
        
        if(chart == null){            
            console.getErr().println(instrument + "のチャートが開かれていません");
            context.stop(); // ストラテジー停止
        }
        
        // 15期間のRSI追加
        IChartPanel rsiPanel = chart.add(
                                   indicators.getIndicator("RSI"),
                                   new Object[]{15}
                               );
        
        // 同じパネルに他RSI追加
        rsiPanel.add(
             indicators.getIndicator("RSI"),
             new Object[]{30},
             new Color[]{Color.MAGENTA},
             new DrawingStyle[]{DrawingStyle.LINE},
             new int[]{1}
         );
        
        // 水平線追加
        IHorizontalLineChartObject hLine = chart.getChartObjectFactory().createHorizontalLine("subHLine", 50);
        hLine.setColor(Color.RED);
        hLine.setLineStyle(LineStyle.DASH_DOT_DOT);
        rsiPanel.add(hLine);
        
        
        // isOverChart()=trueのインジケータはチャートパネルに追加できません。
        IndicatorInfo emaInfo = indicators.getIndicator("EMA").getIndicatorInfo();
        if(emaInfo.isOverChart() && rsiPanel instanceof IIndicatorPanel){
            console.getOut().println( emaInfo.getName() + 
                                     "は、メインチャートへのプロットのみ可能なので、インジケータパネルに追加できません。");
        }
    }

    @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 {
        
        // 全インジケータパネルを削除
        while(chart.getIndicatorPanels().size() > 0){
            IChartPanel panel = chart.getIndicatorPanels().get(0);
            for (IIndicator indicator : panel.getIndicators()) {
              panel.removeIndicator(indicator);
            }
        }
    }

}








スポンサーリンク

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


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


Top

inserted by FC2 system