Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Best way to use indicators on strategy
 Post subject: Best way to use indicators on strategy Post rating: 0   New post Posted: Thu 07 Jun, 2012, 22:20 

User rating: 1
Joined: Fri 04 May, 2012, 21:03
Posts: 5
Hi support,

I've create a strategy that add on chart two indicators like this:

public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
        _principal=null;
        time.add(Calendar.HOUR_OF_DAY, 2);
        this._chart=context.getChart(_instrument);
       
        _indBBANDS = indicators.getIndicator("BBANDS");
        _indSMA = indicators.getIndicator("SMA");
        printIndicatorInfos(_indSMA);
       
        this._chart.addIndicator(_indBBANDS, new Object[]{_bbperiod, _bbup, _bbdown, _bbmatype.ordinal()}, new Color[]{Color.RED, Color.GREEN, Color.RED},new OutputParameterInfo.DrawingStyle[]{OutputParameterInfo.DrawingStyle.LINE, OutputParameterInfo.DrawingStyle.LINE, OutputParameterInfo.DrawingStyle.LINE}, new int[]{1, 1, 1});
        this._chart.addIndicator(_indSMA, new Object[]{_smaperiod}, new Color[]{Color.BLUE},new OutputParameterInfo.DrawingStyle[]{OutputParameterInfo.DrawingStyle.LINE}, new int[]{1});
    }


Now, if every tick i want read the values from that indicators how I can do?

public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != _instrument) {
            return;
        }
        double SMAvalue=//TODO: get value from _indSMA;
        double[]BBANDS=//TODO: get value from _indBBANDS;
    }


Thank's


 
 Post subject: Re: Best way to use indicators on strategy Post rating: 0   New post Posted: Mon 11 Jun, 2012, 13:58 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Here is an example
        double smaValue = indicators.sma(Instrument.EURUSD, Period.TEN_MINS, OfferSide.BID, AppliedPrice.CLOSE, 10,
                Filter.ALL_FLATS, 1, history.getLastTick(Instrument.EURUSD).getTime(), 0)[0];
        double[] bbasds = indicators.bbands(Instrument.EURUSD, Period.TEN_MINS, OfferSide.BID, AppliedPrice.CLOSE, 30, 1, 1, MaType.EMA,
                Filter.ALL_FLATS, 1, history.getLastTick(Instrument.EURUSD).getTime(), 0)[0];


For more information please see https://www.dukascopy.com/wiki/#Indicators.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com