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.

Why the price displayed by the platform is different from the strategy??
 Post subject: Why the price displayed by the platform is different from the strategy?? Post rating: 0   New post Posted: Tue 17 Apr, 2018, 03:27 

User rating: 0
Joined: Mon 11 Dec, 2017, 03:30
Posts: 26
Location: China,
I wrote some simple code, found some problems, took the day's opening price, and the closing price was different from by the platform displayed:
Please tell me what the reason is
Examples are as follows:

public class GetBarsExample implements IStrategy {
@Configurable("Instrument")
public Instrument Curinstrument = Instrument.AUDJPY;

private IContext context;
private IConsole console;
private IHistory history;
private IBar prevDailyBar;
private SimpleDateFormat gmtSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

public void onStart(IContext context) throws JFException {
this.context = context;
console = context.getConsole();
history = context.getHistory();

context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
//today BARS
prevDailyBar = history.getBar(Curinstrument, Period.DAILY, OfferSide.ASK, 0);

console.getInfo().format(" today open price=%.5f ", prevDailyBar .getOpen()).println();

console.getInfo().format(" today time=%s open price=%.5f close price=%.5f ",gmtSdf.format(prevDailyBar.getTime()),prevDailyBar .getOpen(), prevDailyBar .getClose()).println();
}
console printinfo:
today time=2018-04-17 08:00:00 open price=83.24000 close price=83.21800

but he platform displayed:
4-17 (aud/jpy today open price is 83.312
Image


Attachments:
openpriceErr.jpg [253.7 KiB]
Downloaded 273 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Why the price displayed by the platform is different from the strategy?? Post rating: 0   New post Posted: Wed 18 Apr, 2018, 08:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello.
history.getBar() gets bars using GMT Timezone. Platform displays prices depending on your chart Timezone settings. You can check it in:
Settings - Preferences - Chart - Day Start Time.
If you will switch it to GMT, price from history.getBar() and in OHLC widget will be identical.


 
 Post subject: Re: Why the price displayed by the platform is different from the strategy?? Post rating: 0   New post Posted: Thu 19 Apr, 2018, 05:54 

User rating: 0
Joined: Mon 11 Dec, 2017, 03:30
Posts: 26
Location: China,
oh,i see.thanks.

There is also a question of how to take the opening price in different time zones???


 
 Post subject: Re: Why the price displayed by the platform is different from the strategy?? Post rating: 0   New post Posted: Fri 27 Apr, 2018, 15:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can implement some custom method, pass timezone and date to it and use SimpleDateFormat as a timezone switcher.
Example:

@Configurable("TimeZone")
 public String timezoneAsString;


    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (Curinstrument != instrument || this.period != period) {
            return;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(askBar.getTime());

        IBar barByTimeZone = getBarByTimeZone(timezoneAsString, calendar);

        console.getInfo().format(" %s, today time=%s open price=%.5f close price=%.5f ", timezoneAsString, dateFormat.format(barByTimeZone.getTime()),
                barByTimeZone.getOpen(), barByTimeZone.getClose()).println();
    }


    private IBar getBarByTimeZone(String timezoneAsString, Calendar date) {
        long barTime = 0;

        try {
            dateFormat.setTimeZone(TimeZone.getTimeZone(timezoneAsString));
            Date dateFrom = dateFormat.parse(sdf.format(date.getTime()));
            barTime = dateFrom.getTime();
        } catch (Exception e) {
            console.getErr().println(e.getMessage());
        }

        if (barTime != 0) {
            try {
                List<IBar> barsByTime = history.getBars(Curinstrument, period, OfferSide.ASK, barTime , barTime);
                if (barsByTime.size() <= 1) {
                    return barsByTime.get(0);
                }

            } catch (Exception exc) {
                console.getErr().println(exc.getMessage());
            }
        }

        return null;
    }


 

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