Dukascopy
 
 
Wiki JStore Search Login

history.getBar() returns incorrect values in some cases
 Post subject: history.getBar() returns incorrect values in some cases Post rating: 0   New post Posted: Fri 04 May, 2018, 12:48 

User rating: 0
Joined: Tue 09 May, 2017, 23:05
Posts: 14
IBar previousBar = history.getBar(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.BID, 1);  
writeToFile(previousBar.getClose(), time);


When the new bar is created, if the end of previous bar was volatile, previousBar.getClose() returns incorrect value.
And keeps returning same value in the following ticks, but if I restart the strategy, it is starting to log the correct value (the same with the chart).


You can reproduce the case by logging close and open prices for 1-2 days and compare logged close prices with historical data with following code.

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (!instrument.equals(Instrument.EURUSD)) return;         
        if(period.equals(Period.ONE_HOUR)){         
            newBar = history.getBar(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.BID, 0); //I also tried getBars method with bidBar.getTime parameter but same thing happens.
            previousBar = history.getBar(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.BID, 1);         
            writeToLog(previousBar.getClose() + " " + newBar.getOpen() + "");
    }
 
    public void writeToLog(String text){
        try{
            FileWriter fileOpenWidthAppendMode = new FileWriter("C:/Users/Ugur/Documents/Visual Studio 2015/Projects/Unicorn/Unicorn/log_test.txt", true);
            BufferedWriter contentToWrite = new BufferedWriter(fileOpenWidthAppendMode);
            contentToWrite.append(text + "\r\n");
            contentToWrite.close();
        }catch(Exception e){
                 
        }       
    }


 

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