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.

Using IHistory in indicator...
 Post subject: Using IHistory in indicator... Post rating: 0   New post Posted: Wed 04 Apr, 2012, 15:37 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
Hello,
First of all, i'm a beginner ;)
Is it possible to use the following code, and if yes, how i must use it ?

 
...
import com.dukascopy.api.feed.*;

public class MyForexIndex implements IIndicator {
...
private IHistory history;
private IBar myBar;

...
public void onStart(IIndicatorContext context) {
       
      IHistory history=context.getHistory();
      myBar=history.getBar(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.ASK, 5);
...


When i try to compile it, i have an unhandled exception type JFException...

Did i'm not using this function as it musr be used ?

By advance, thanks.


 
 Post subject: Re: Using IHistory in indicator... Post rating: 1   New post Posted: Wed 04 Apr, 2012, 17:07 

User rating: 5
Joined: Thu 29 Mar, 2012, 15:00
Posts: 19
All of the methods in IStrategy (onBar, onStart, onTick, etc.) can throw JFException. Therefore you need to change your method to:

public void onStart(IIndicatorContext context) throws JFException {
       
      IHistory history=context.getHistory();
      myBar=history.getBar(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.ASK, 5);
}


 
 Post subject: Re: Using IHistory in indicator... Post rating: 0   New post Posted: Thu 05 Apr, 2012, 02:55 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
Thanks tommy5d.
However, when i try to compile it, an error occurs:

Quote:
Exception JFException is not compatible with throws clause in IIndicator.onStart(IIndicatorContext)


Ant idea ?

Thanks


 
 Post subject: Re: Using IHistory in indicator... Post rating: 0   New post Posted: Thu 05 Apr, 2012, 07:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
What are you trying to do? Are you trying to make a strategy or an indicator?


 
 Post subject: Re: Using IHistory in indicator... Post rating: 0   New post Posted: Thu 05 Apr, 2012, 12:34 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
I'm trying to make an indicator.


 
 Post subject: Re: Using IHistory in indicator... Post rating: 0   New post Posted: Thu 05 Apr, 2012, 13:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You need to handle the JFException, i.e. surround it with a try-catch block, as it is done in the following indicator (see lines 80 and 91):
viewtopic.php?f=6&t=42796


 
 Post subject: Re: Using IHistory in indicator... Post rating: 0   New post Posted: Thu 05 Apr, 2012, 16:32 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
Thanks for you help ! Everything is working now !

Thanks again !


 

Jump to:  

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