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.

RESOLVED Function getBar() seems to crash onBar()
 Post subject: RESOLVED Function getBar() seems to crash onBar() Post rating: 0   New post Posted: Thu 02 Jul, 2009, 20:23 

User rating: 0
Joined: Tue 30 Jun, 2009, 20:38
Posts: 17
Hi. I am writing my first strategy, and I believe I have found a bug. I am using the strategy tester and only EUR/USD on hour ask bars. In my onBar() method I write some stuff to a file, then call getBar, and then write more stuff to a file. However, after the call to getBar, nothing more gets written to my file. I moved the getBar call to the beginning of onBar() and now nothing gets written to my file! If I comment out the getBar call then everything works as it should. Here are relevant snippets:

public class DataDownloader implements IStrategy {
    private IContext context = null;
    private IEngine engine = null;
    private IChart chart = null;
    private IIndicators indicators = null;
    private IHistory history = null;
    private IBar ibar = null;
}

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
      ibar = history.getBar(instrument, period, OfferSide.ASK, 1);


On a side note, it looks like I am receiving a lot of douplicate data. Here is an example:

Quote:
1245888060000,EUR/USD:1.39485
1245888070000,EUR/USD:1.39445
1245888080000,EUR/USD:1.39445
1245888090000,EUR/USD:1.3946
1245888100000,EUR/USD:1.3946
1245888060000,EUR/USD:1.39485
1245888110000,EUR/USD:1.3946
1245888120000,EUR/USD:1.3945
1245888130000,EUR/USD:1.3945
1245888140000,EUR/USD:1.39465
1245888150000,EUR/USD:1.39455
1245888160000,EUR/USD:1.3947
1245888120000,EUR/USD:1.3945
1245888170000,EUR/USD:1.3945


Surely this should be fixed on the server side? I could pretty easily code something to check for duplicate data, but I would think that Dukascopy would want to fix something as simple as this on their end to provide better quality service... Or maybe this is just a demo thing? Does the data from a real live account contain duplicates like this? There seems to be one duplicate for every ten bars on average...


 
 Post subject: Re: Function getBar() seems to crash onBar() Post rating: 0   New post Posted: Thu 02 Jul, 2009, 20:34 

User rating: 0
Joined: Tue 30 Jun, 2009, 20:38
Posts: 17
Note: I get the following error from jForex with the ibar=history.getbar(... line un-commented:

java.lang.NullPointerException @ DataDownloader.DataDownloader.onBar(DataDownloader.java:29)


 
 Post subject: Re: Function getBar() seems to crash onBar() Post rating: 0   New post Posted: Thu 02 Jul, 2009, 21:02 

User rating: 0
Joined: Tue 30 Jun, 2009, 20:38
Posts: 17
My code doesn't work when I run the strategy live on the demo account either (rather than using the tester). I must be using something improperly... Does somebody see my mistake?


 
 Post subject: Re: RESOLVED Function getBar() seems to crash onBar() Post rating: 0   New post Posted: Thu 02 Jul, 2009, 21:45 

User rating: 0
Joined: Tue 30 Jun, 2009, 20:38
Posts: 17
I found it, it was pretty obvious - I never assigned anything to the variable history, I just left it at null.

I have discovered another problem though. getBar with a shift of 1 returns the same open price as askBar (the current bar). Isn't getBar with a shift of 0 supposed to be the current bar?


 
 Post subject: Re: RESOLVED Function getBar() seems to crash onBar() Post rating: 0   New post Posted: Fri 03 Jul, 2009, 02:13 

User rating: 0
Joined: Tue 30 Jun, 2009, 20:38
Posts: 17
Copy/pasting from my other thread, this is concerning the duplicate data I had written in my file.
Quote:
OK, I figured it out, but it doesn't make sense to me. When using the strategy tester you have to select a period to test on, but it doesn't seem to matter what you select because the strategy will be run on all periods at the same time, starting with the 10 second bars and moving up. This is probably why I was seeing duplicate data before, because the strategy will be run on the same bars multiple times if that bar is the opening time for more than one period.

This really doesn't make sense to me - why would you allow the user to select what period to test on, but then require that the strategy filter out the bars that it wants to run on? It seems like you should either get rid of the ability to choose a period to test on, or make it so that the strategy is only run on the period specified. But w/e, I will make it work by putting everything in my onBar function under anf "if (period = "Desired Period")" statement.


 
 Post subject: Re: RESOLVED Function getBar() seems to crash onBar() Post rating: 0   New post Posted: Fri 03 Jul, 2009, 10:45 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
triwebb1 wrote:
I have discovered another problem though. getBar with a shift of 1 returns the same open price as askBar (the current bar). Isn't getBar with a shift of 0 supposed to be the current bar?

0 is the bar that is not fully formed yet, "in-progress" bar. It changes as more ticks coming to fill it. 1 is the index of last formed bar, onBar called only on fully formed bars, so 1 is the same bar as askBar that you get in parameters


 

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