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.

Can't get chart object
 Post subject: Can't get chart object Post rating: 0   New post Posted: Wed 19 Oct, 2011, 21:04 

User rating: -
Hello,

I'm new to JForex and I'm not quite sure if this is a bug or I'm simply missing some step in making my strategy work. The problem is that when I start a strategy and try to add an indicator, the chart object is null. Here is what I do...

First I connect and then subscribe to an instrument and start the strategy with this code:
        ...
        Set<Instrument> instruments = new HashSet<Instrument>();
        instruments.add(Instrument.EURUSD);
        client.setSubscribedInstruments(instruments);
        client.startStrategy(new MyStrategy());


In the strategy class MyStrategy in the method onStart I have put this code:
        indicators = context.getIndicators();
        IChart chart = context.getChart(Instrument.EURUSD);
        chart.addIndicator(indicators.getIndicator("STOCH"));


The problem is that chart is null and when trying to add the indicator an exception is thrown. I have searched for a solution for this problem, but I didn't find anything. Moreover, all examples that I found do it in this way. Is there a need to add this chart somehow before getting it from the context? I tried to find a way to add a chart but I didn't came upon an appropriate method. Or I may miss something else?

Please help and thank you in advance!


 
 Post subject: Re: Can't get chart object Post rating: 0   New post Posted: Thu 20 Oct, 2011, 16:03 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can't access charts from Standalone API. You can do this only when backtesting with TesterMainGUIMode.


 
 Post subject: Re: Can't get chart object Post rating: 0   New post Posted: Fri 21 Oct, 2011, 08:35 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
Actually, I don't need to use chart but indicators and the only way I found to use indicators in the code is by adding them to a chart. Is there a way to use indicators in a strategy used from standalone API? If so, please provide some details.


 
 Post subject: Re: Can't get chart object Post rating: 0   New post Posted: Fri 21 Oct, 2011, 09:47 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
dspetrov wrote:
Actually, I don't need to use chart but indicators and the only way I found to use indicators in the code is by adding them to a chart.
That is not the case, you can get indicator values regardless if they are plotted on the chart or not.
dspetrov wrote:
Is there a way to use indicators in a strategy used from standalone API? If so, please provide some details.
See: https://www.dukascopy.com/wiki/index.php ... Indicators


 
 Post subject: Re: Can't get chart object Post rating: 0   New post Posted: Mon 24 Oct, 2011, 15:30 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
Thank you very much for the quick answers - they were helpful! :)


 

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