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.

Print problem
 Post subject: Print problem Post rating: 0   Post Posted: Sun 05 Dec, 2010, 17:41 

User rating: 0
Joined: Mon 11 Oct, 2010, 13:42
Posts: 8
Hello everyone,

this might be a stupid question, but as I'm a newbie, it's important to understand one's mistakes.

I have this code:

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (instrument.equals(currentInstrument)) {
           
                  ask = askBar.getClose();
                  bid = bidBar.getClose();
                  orderList = engine.getOrders(currentInstrument); 

                   IBar bar1 = history.getBar(instrument, period, OfferSide.ASK, 1);
                   IBar bar2 = history.getBar(instrument, period, OfferSide.ASK, 2);                                   

                   double close_bar1 = bar1.getClose();
                   double close_bar2 = bar2.getClose();
                   double vol_bar2 = bar2.getVolume();
                   
                   console.getOut().println("Bar value:" + close_bar1);
                   console.getOut().println("Bar2 value:" + close_bar2);
                   console.getOut().println("ask value:" + ask);   
           
            try {
                if (positionsTotal(instrument) < positionsAmount) {
           

                   
                } else if ((positionsTotal(instrument) > 0)) {
(...)


I just want to print out the values, but it doesn't print anything in historical test.

Compiling is successful. What am I doing wrong?


 
 Post subject: Re: Print problem Post rating: 0   Post Posted: Mon 06 Dec, 2010, 14:46 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Please be sure that you have selected correct currency and checked messages check box in the historical tester tab


 
 Post subject: Re: Print problem Post rating: 0   Post Posted: Mon 06 Dec, 2010, 16:06 

User rating: 0
Joined: Mon 11 Oct, 2010, 13:42
Posts: 8
1. The Messages box is checked and the instrument is correct, too.

2. I tried another code I found on the Historical Data page in wiki.

SimpleDateFormat dateFormat dateFormat = new SimpleDateFormat("dd/MM/yyy HH:mm:ss"); 
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
    Date dateFrom = dateFormat.parse("05/10/2008 00:00:00");
    Date dateTo = dateFormat.parse("04/10/2010 00:00:00");
} catch (ParseException e) {
    e.printStackTrace();
}   
List<IBar> bars = history.getBars(Instrument.EURUSD, Period.DAILY, OfferSide.ASK, dateFrom.getTime(), dateTo.getTime());


It took me hours to find out that I have to import some more packages in order to recognize the types. What I still don't understand is how to convert the Date type to the long type which is required by getTime().

**Edit**
Problem 1 solved. I just saw this thread https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=19&t=4284&p=6237&hilit=Historical+data#p6237
I didn't know that in historical tester messages are printed in the tab itself and not in the messages tab.

But why does it print out data for every tick?
Is the getClose() method not working in HT?
**

**Re-Edit**
I fixed the first problem.
But the values I get are strange.
Please consider some of the messages for Eur/Usd, 24.11.2010 - 25.11.2010, five minute bars

Quote:
16:15:42 24.11.2010_23:59:50 Price: 1.33588 Volume: 3.6
16:15:42 24.11.2010_23:59:00 Price: 1.33588 Volume: 45.1
16:15:42 24.11.2010_23:55:00 Price: 1.33588 Volume: 143.9
16:15:42 24.11.2010_23:50:00 Price: 1.33588 Volume: 272.9
16:15:42 24.11.2010_23:45:00 Price: 1.33588 Volume: 368.8
16:15:42 24.11.2010_23:30:00 Price: 1.33588 Volume: 785.7
16:15:42 24.11.2010_23:00:00 Price: 1.33588 Volume: 1509.2
16:15:42 24.11.2010_20:00:00 Price: 1.33588 Volume: 6045.0
16:15:42 24.11.2010_00:00:00 Price: 1.33588 Volume: 86395.0
16:15:42 24.11.2010_23:59:40 Price: 1.33584 Volume: 1.5
16:15:42 24.11.2010_23:59:30 Price: 1.33577 Volume: 8.9
16:15:42 24.11.2010_23:59:20 Price: 1.33576 Volume: 7.6
16:15:42 24.11.2010_23:59:10 Price: 1.33562 Volume: 6.0
16:15:42 24.11.2010_23:59:00 Price: 1.33583 Volume: 17.5
16:15:42 24.11.2010_23:58:50 Price: 1.33596 Volume: 8.1
16:15:42 24.11.2010_23:58:00 Price: 1.33596 Volume: 48.9
16:15:42 24.11.2010_23:58:40 Price: 1.33603 Volume: 2.7
16:15:42 24.11.2010_23:58:30 Price: 1.33604 Volume: 19.9
16:15:42 24.11.2010_23:58:20 Price: 1.33612 Volume: 12.8
16:15:42 24.11.2010_23:58:10 Price: 1.33595 Volume: 0.0
16:15:42 24.11.2010_23:58:00 Price: 1.33595 Volume: 5.4
16:15:42 24.11.2010_23:57:50 Price: 1.3359 Volume: 3.0
16:15:42 24.11.2010_23:57:00 Price: 1.3359 Volume: 23.2
16:15:42 24.11.2010_23:57:40 Price: 1.33583 Volume: 1.5


I was using this code:

          IBar bar = history.getBar(instrument, period, OfferSide.ASK, 1);

                   double close_bar = bar.getClose();

                   double barVolume = bar.getVolume();
                   long currentBarTime = bar.getTime();
                   
                   console.getOut().println(sdf.format(currentBarTime) + " Price: " + close_bar + " Volume: " + barVolume);


Why does it print only one hour of 24/11/2010?
And why are the differenet start times of the bars not 5 Minutes after one another?
Is this a bug?


 
 Post subject: Re: Print problem Post rating: 0   Post Posted: Tue 07 Dec, 2010, 11:51 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
thomey wrote:
But why does it print out data for every tick?

If you choose test for tick, that output data will be for every tick, you can change this setting in the historical tester tab under the currency pair combo box. For example if you open 30 Mins and Tick on Open you will receive message only after the 30 min bar opens.
thomey wrote:
And why are the differenet start times of the bars not 5 Minutes after one another?
Is this a bug?

You can filter bars to get messages only for 5 Minutes bars:
if (instrument.equals(Instrument.EURUSD) && period.equals(Period.FIVE_MINS)) {
}

Please consider the following JForex Wiki page: https://www.dukascopy.com/wiki/index.php ... Ticks/Bars


 

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