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.

Major bug in IHistory.getBar
 Post subject: Major bug in IHistory.getBar Post rating: 0   New post Posted: Mon 06 Dec, 2010, 09:00 

User rating: 0
Joined: Sun 11 Jul, 2010, 20:12
Posts: 20
I just discovered that the IHistory.getbar method does not behave as expected when called soon after a weekend. Suppose it is now Monday morning 6:30AM GMT and I want to get the bar that is 60 completed 15 minute bars back in time. I had assumed that the getBar method would skip Saturday and Sunday (since the market is closed then) and give me the data at the 60th trading bar ago, ie the bar at 1530 GMT on Friday.

Unfortunately, JForex apparently implemented the getBar method so that if I request 60 bars ago (15 minute bars), it gives me the data at exactly 15 hours ago, EVEN IF THIS IS IN THE MIDDLE OF THE WEEKEND AND THE MARKET IS CLOSED!

Dukascopy: This really screws up calculations like momentum where I am looking at exactly 60 trading bars ago. It should NOT include imaginary 15 minute bars over the weekend!

Please comment on this And if you plan to fix this, PLEASE TELL US FIRST because I already implemented a quick and dirty hack to get around it and I don't want you to break my code.


 
 Post subject: Re: Major bug in IHistory.getBar Post rating: 0   New post Posted: Wed 08 Dec, 2010, 08:08 

User rating: 0
Joined: Sun 11 Jul, 2010, 20:12
Posts: 20
No comment from support yet?


 
 Post subject: Re: Major bug in IHistory.getBar Post rating: 0   New post Posted: Wed 15 Dec, 2010, 15:33 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please use IHistory.getBars method that accepts (Instrument instrument, Period period, OfferSide side, Filter filter, int numberOfCandlesBefore, long time, int numberOfCandlesAfter) parameters. Pass Filter.WEEKENDS as filter parameter


 
 Post subject: Re: Major bug in IHistory.getBar Post rating: 0   New post Posted: Sat 05 Mar, 2011, 04:13 

User rating: 1
Joined: Sun 05 Dec, 2010, 08:44
Posts: 21
Support wrote:
Please use IHistory.getBars method that accepts (Instrument instrument, Period period, OfferSide side, Filter filter, int numberOfCandlesBefore, long time, int numberOfCandlesAfter) parameters. Pass Filter.WEEKENDS as filter parameter


This means that we have to use the more complicated version of indicators if we want indicators to work the way they normally should. I don't think anybody expects for indicators to calculate on Saturday bars by default, because the market is closed on Saturday.

e.g. for sma you have three different versions:

 double[]    sma(Instrument instrument, Period period, OfferSide side, IIndicators.AppliedPrice appliedPrice, int timePeriod, Filter filter, int numberOfCandlesBefore, long time, int numberOfCandlesAfter)
           
 double    sma(Instrument instrument, Period period, OfferSide side, IIndicators.AppliedPrice appliedPrice, int timePeriod, int shift)
           
 double[]    sma(Instrument instrument, Period period, OfferSide side, IIndicators.AppliedPrice appliedPrice, int timePeriod, long from, long to)
         


The second method that returns a double is the simplest, but it does not accept a Filter, so the sma values on Sunday night or early Monday morning are going to be based on calculations on Saturday bars. The only option we have in order to skip Saturday bars is the first one that returns an array and for which we have to pass in the time of the current bar and how many bars before and after we want the indicator value for. I think using this more complex version would reduce performance unnecessarily. Often we don't need the increased complexity - we just want the latest indicator value, or one previous value (using the shift parameter).

Is it possible for you to add the Filter parameter to the simple version of the indicators so that we can exclude Saturday bars and still use the simple version, like this?:
 double    sma(Instrument instrument, Period period, OfferSide side, IIndicators.AppliedPrice appliedPrice, int timePeriod, Filter filter, int shift)


 
 Post subject: Re: Major bug in IHistory.getBar Post rating: 0   New post Posted: Sat 05 Mar, 2011, 06:13 

User rating: 1
Joined: Sun 05 Dec, 2010, 08:44
Posts: 21
To see the difference between using a filter and not, I tried the following code in onBar over EURUSD:

       if (period == Period.DAILY) {
            Calendar calendar1 = new GregorianCalendar();
            calendar1.setTimeInMillis(bidBar.getTime()); //open time of just-closed daily bar
            if (calendar1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { //new Monday
                double atrNoFilter = indicators.atr(instrument, Period.ONE_HOUR, OfferSide.BID, 50, 0);
                long currentBarTime = history.getBar(instrument, period, OfferSide.BID, 0).getTime();
                double atrFilterWeekends = indicators.atr(instrument, Period.ONE_HOUR, OfferSide.BID, 50, Filter.WEEKENDS, 0, currentBarTime, 1)[0];
               console.getOut().println("ATR without filter = " + atrNoFilter / instrument.getPipValue() + ", ATR with filter = " + atrFilterWeekends / instrument.getPipValue());
            }
}


Both atr calls are for 50 hourly bars.
The first uses the simple version (which has no filter parameter).
The second uses the more complex version with filter parameter. It requires a prior call to getBar in order to get the time of the new bar. We can't just use bidBar.getTime() because that returns the open time of the just-completed old daily bar.

Here an example of the output:
ATR without filter = 12.597251482197422, ATR with filter = 32.99297477694337


You can see that there is a big difference because Saturday bars (which are all flat) are being used in the simple indicator version.

It would be so much easier if, instead of using the complex version of the indicator just to be able to use the filter, we could do this:
double atrNoFilter = indicators.atr(instrument, Period.ONE_HOUR, OfferSide.BID, 50, Filter.WEEKENDS, 0);


 
 Post subject: Re: Major bug in IHistory.getBar Post rating: 0   New post Posted: Mon 07 Mar, 2011, 14:59 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hyperdimension wrote:
Is it possible for you to add the Filter parameter to the simple version of the indicators so that we can exclude Saturday bars and still use the simple version, like this?:
 double    sma(Instrument instrument, Period period, OfferSide side, IIndicators.AppliedPrice appliedPrice, int timePeriod, Filter filter, int shift)

We will consider your suggestion.


 

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