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.

Get indicator values (BBANDS)
 Post subject: Get indicator values (BBANDS) Post rating: 0   New post Posted: Thu 20 Aug, 2015, 16:41 
User avatar

User rating: 0
Joined: Mon 04 May, 2015, 05:43
Posts: 4
Location: Russian Federation, Saint-Petersburg
Hello, please help me. I started develop new strategy, and cant get values of indicator...

Open new chart:
        this.feedDescriptor = new FeedDescriptor();
       
        this.feedDescriptor.setDataType(DataType.TICKS);
        this.feedDescriptor.setInstrument(this.instrument_current);
        this.feedDescriptor.setPeriod(Period.TICK);
        this.feedDescriptor.setOfferSide(OfferSide.BID);
        this.feedDescriptor.setFilter(Filter.WEEKENDS);
       
        this.chart = context.openChart(this.feedDescriptor);


Add indicator on chart:
        BBANDS = indicators.getIndicator("BBANDS");
       
        this.chart.add(
            BBANDS,
            new Object[]{80, 2.0, 2.0, MaType.SMMA.ordinal()},
            new Color[]{Color.yellow, Color.orange, Color.yellow},
            new OutputParameterInfo.DrawingStyle[]{OutputParameterInfo.DrawingStyle.LINE, OutputParameterInfo.DrawingStyle.DASH_LINE, OutputParameterInfo.DrawingStyle.LINE},
            null);


And how can i get values of this indicator on TICK chart ???


 
 Post subject: Re: Get indicator values (BBANDS) Post rating: 0   New post Posted: Wed 02 Sep, 2015, 08:06 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Last chart outputs can be obtained through IChart.getLastCalculatedIndicatorOutputs().

package jforex;
 
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.MaType;
import com.dukascopy.api.feed.FeedDescriptor;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.OutputParameterInfo.DrawingStyle;
import com.dukascopy.api.indicators.OutputParameterInfo;
 
import java.awt.Color;
import java.util.*;
 
public class Strategy implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
   
    @Configurable("Instrument")
    public Instrument instrument_current = Instrument.EURUSD;
   
    private FeedDescriptor feedDescriptor;
    private IChart chart;
    private IIndicator BBANDS;
   
    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();
       
        this.feedDescriptor = new FeedDescriptor();
       
        this.feedDescriptor.setDataType(DataType.TICKS);
        this.feedDescriptor.setInstrument(this.instrument_current);
        this.feedDescriptor.setPeriod(Period.TICK);
        this.feedDescriptor.setOfferSide(OfferSide.BID);
        this.feedDescriptor.setFilter(Filter.WEEKENDS);
       
        this.chart = context.openChart(this.feedDescriptor);
       
        BBANDS = indicators.getIndicator("BBANDS");
 
        this.chart.add(
            BBANDS,
            new Object[]{80, 2.0, 2.0, MaType.SMMA.ordinal()},
            new Color[]{Color.yellow, Color.orange, Color.yellow},
            new OutputParameterInfo.DrawingStyle[]{OutputParameterInfo.DrawingStyle.LINE, OutputParameterInfo.DrawingStyle.DASH_LINE, OutputParameterInfo.DrawingStyle.LINE},
            null);
    }
 
    public void onAccount(IAccount account) throws JFException {
    }
 
    public void onMessage(IMessage message) throws JFException {
    }
 
    public void onStop() throws JFException {
    }
 
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        Map<IIndicator, Object[]> outputs = chart.getLastCalculatedIndicatorOutputs();
        Object[] values = outputs.get(BBANDS);
        if (values != null) {
            for (int i = 0; i < values.length; i++) {
                double[] doubles = (double[]) values[i];
                console.getOut().println(i + " : " + Arrays.toString(doubles));
            }
        }
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


 

Jump to:  

cron
  © 1998-2024 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