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.

Troubles while testing with ITesterClient
 Post subject: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Mon 24 Oct, 2011, 14:14 

User rating: 0
Joined: Mon 24 Oct, 2011, 14:12
Posts: 5
Location: Russian Federation,
Now I'm studying JForex API. Yesterday I faced with some troubles.
I made simple strategy based on crossing moving averages. I use ITesterClient.
I use onBar method to analyse market condition:

   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (period != timeframe) return;
        if (!shouldProcess(instrument)) return;
        long time = history.getPreviousBarStart(period, askBar.getTime());
        double[] fast = indicators.ma(instrument,
                                      this.timeframe,
                                      this.offerSide,
                                      this.appliedPrice,
                                      this.fast,
                                      MaType.SMA,
                                      this.maFilter,
                                      2,
                                      time,
                                      0);
        double[] slow = indicators.ma(instrument,
                                      this.timeframe,
                                      this.offerSide,
                                      this.appliedPrice,
                                      this.slow,
                                      MaType.SMA,
                                      this.maFilter,
                                      2,
                                      time,
                                      0);

        BigDecimal[] _fast = {new BigDecimal(fast[0], mathContext),
                              new BigDecimal(fast[1], mathContext)};
        BigDecimal[] _slow = {new BigDecimal(slow[0], mathContext),
                              new BigDecimal(slow[1], mathContext)};

        if (fast[0] > slow[0] && fast[1] < slow[1]) {
            LOGGER.info(df.format(new Date(askBar.getTime())) + ": SELL. ");
            LOGGER.info(df.format(new Date(time)) + ": "
                    + "[2]= [" + _fast[1] + "]/[" + _slow[1] + "] "
                    + "[1]= [" + _fast[0] + "]/[" + _slow[0] + "]");
            closeLongOrders();
            submitOrder(instrument, IEngine.OrderCommand.SELL, bidBar.getOpen(), "Sell");
        }
        if (fast[0] < slow[0] && fast[1] > slow[1]) {
            LOGGER.info(df.format(new Date(askBar.getTime())) + ": BUY. ");
            LOGGER.info(df.format(new Date(time)) + ": "
                    + "[2]= [" + _fast[1] + "]/[" + _slow[1] + "] "
                    + "[1]= [" + _fast[0] + "]/[" + _slow[0] + "]");
            closeShortOrders();
            submitOrder(instrument, IEngine.OrderCommand.BUY, askBar.getOpen(), "Buy");
        }
    }


the first trouble
If I start running from 1/01/2011 I've got next messages in the log:
24.10.2011 16:46:17 DEBUG Thread-5 Reading ticks from chunk file [/home/eugene/JForex/.cache/EURUSD/2011/01/27/22h_ticks.bi5] com.dukascopy.charts.data.datacache.CacheManager
24.10.2011 16:46:17 INFO StrategyRunner Thread 25.02.2011 22:00:00: BUY
24.10.2011 16:46:17 INFO StrategyRunner Thread 25.02.2011 21:45:00: [2]= [1.37514]/[1.37510] [1]= [1.37495]/[1.37511] 24.10.2011 16:46:17 DEBUG StrategyRunner Thread Exiting by timeout com.dukascopy.dds2.greed.agent.strategy.tester.StrategyRunner
24.10.2011 16:46:17 DEBUG StrategyRunner Thread Exiting by timeout com.dukascopy.dds2.greed.agent.strategy.tester.StrategyRunner
[there are a lot of the same messages. about 2 megabytes]
24.10.2011 16:46:17 INFO StrategyRunner Thread ORDER_SUBMIT_REJECTED: System offline
there system stop only after System.exit(1) had been added into submitOrder

 private void submitOrder(Instrument instrument,
                             IEngine.OrderCommand orderCmd,
                             double price,
                             String label) throws JFException {
        IOrder order = engine.submitOrder(label, instrument, orderCmd, amount, price, slippage);

        IMessage message;
        while (order.getState() == IOrder.State.CREATED || order.getState() == IOrder.State.OPENED) {
            message = order.waitForUpdate(2, TimeUnit.SECONDS);
            if (message != null) {
                this.context.getConsole().getOut().println(message.getContent());
                LOGGER.info(message.getType() + ": " + message.getContent());
                if (message.getType() == IMessage.Type.ORDER_SUBMIT_REJECTED) System.exit(1);
            }
        }
    }


And the second one
If I start testing from 1/03/2011 The system gets the same values of MAs for two serial bars:
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 20:45:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:15:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
I can't understand how it can be
so I've got error message:
24.10.2011 16:31:36 ERROR StrategyRunner Thread Cannot create order with label that already exists

Could you explain me what are the causes of my troubles?


 
 Post subject: Re: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Mon 24 Oct, 2011, 16:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
eugene wrote:
24.10.2011 16:46:17 INFO StrategyRunner Thread ORDER_SUBMIT_REJECTED: System offline
there system stop only after System.exit(1) had been added into submitOrder
This is because you cannot trade while market is closed (i.e. over the weekends).
eugene wrote:
If I start testing from 1/03/2011 The system gets the same values of MAs for two serial bars:
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 20:45:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:15:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
This can happen if there is no movement in the market and if the MA period is small enough.
eugene wrote:
I can't understand how it can be
so I've got error message:
24.10.2011 16:31:36 ERROR StrategyRunner Thread Cannot create order with label that already exists
This is rather straightforward - you have to ensure that all active orders (those that are not CLOSED or CANCELLED) have unique labels. You can do this either by including a counter in order labels or using an UUID: https://download.oracle.com/javase/1,5.0 ... /UUID.html (though then you have to replace ''-" with "_").

P.S. Please note that the topic soon will get moved to Knowledge base: viewforum.php?f=65


 
 Post subject: Re: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Mon 24 Oct, 2011, 19:49 

User rating: 0
Joined: Mon 24 Oct, 2011, 14:12
Posts: 5
Location: Russian Federation,
API Support wrote:
eugene wrote:
24.10.2011 16:46:17 INFO StrategyRunner Thread ORDER_SUBMIT_REJECTED: System offline
there system stop only after System.exit(1) had been added into submitOrder
This is because you cannot trade while market is closed (i.e. over the weekends).

I see... It explains the situation. I looked through JForex API and found no any appropriate solution. I mean using Filter.WEEKENDS or a way to check market status.
Can you propose the most right way to avoid this problem?
may be can I filter onBar running?
or how can I check is the market opened or closed?

API Support wrote:
eugene wrote:
If I start testing from 1/03/2011 The system gets the same values of MAs for two serial bars:
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 20:45:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:15:00: BUY
24.10.2011 16:31:36 INFO StrategyRunner Thread 25.03.2011 21:00:00: [2]= [1.40821]/[1.40786] [1]= [1.40779]/[1.40813]
This can happen if there is no movement in the market and if the MA period is small enough.

it is the same problem - 25/03/2011 is also a friday.
API Support wrote:
eugene wrote:
I can't understand how it can be
so I've got error message:
24.10.2011 16:31:36 ERROR StrategyRunner Thread Cannot create order with label that already exists
This is rather straightforward - you have to ensure that all active orders (those that are not CLOSED or CANCELLED) have unique labels. You can do this either by including a counter in order labels or using an UUID: https://download.oracle.com/javase/1,5.0 ... /UUID.html (though then you have to replace ''-" with "_").

P.S. Please note that the topic soon will get moved to Knowledge base: viewforum.php?f=65

thanks for quick response


 
 Post subject: Re: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Tue 25 Oct, 2011, 09:24 

User rating: 0
Joined: Mon 24 Oct, 2011, 14:12
Posts: 5
Location: Russian Federation,
I create a method to get weekends for a present

    public static boolean isWeekday(Date date) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cal.setTime(date);
        int month = cal.get(Calendar.MONTH);
        int hour_limit;
        if (month <= Calendar.FEBRUARY || month >= Calendar.OCTOBER) hour_limit = 22;
        else hour_limit = 21;
        int day = cal.get(Calendar.DAY_OF_WEEK);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        if (day == Calendar.SUNDAY && hour >= hour_limit) return true;
        if (day > Calendar.SUNDAY && day < Calendar.FRIDAY) return true;
        if (day == Calendar.FRIDAY && hour < hour_limit) return true;
        return false;
    }


which months are used for a winter working time?

But the problem is still remain.
I use Filter.WEEKENDS to calculate MA and get two values of before the last candles:
indicators.ma(instrument, this.timeframe, this.offerSide, this.appliedPrice, this.slow, MaType.SMA, this.maFilter, 2, time, 0);
And result[0] of current bar and result[1] of last bar are different.

I compare values with GUI FXDD (it is EURUSD, MA are 5 and 20 period SMA):
25/02/11 21:15 [1.37515], [1.37486]
25/02/11 21:30 [1.37511], [1.37495]
25/02/11 21:45 [1.37510], [1.37514]
27/02/11 22:00 [1.37513], [1.37527]
27/02/11 22:15 [1.37513], [1.37551]

24.10.2011 23:57:32 INFO StrategyRunner Thread 25.02.2011 21:30:00: [1.37475]<[1.37517] [1.37486]<[1.37515]
24.10.2011 23:57:32 INFO StrategyRunner Thread 25.02.2011 21:45:00: [1.37486]<[1.37515] [1.37495]<[1.37511]
24.10.2011 23:57:32 INFO StrategyRunner Thread 27.02.2011 22:00:00: [1.37514]>[1.37510] [1.37515]>[1.37510]
24.10.2011 23:57:32 INFO StrategyRunner Thread 27.02.2011 22:15:00: [1.37515]>[1.37510] [1.37536]>[1.37509]

So there are some questions
If the weekends last from 22:00 (>=22:00) Friday to 21:59:59 Monday (<22:00) why I haven't got a crossing of MAs? (as I sad Filter.WEEKENDS is used while calculating MA)
Why the MA's values just after the weekend calculated by API and shown on the chart are different?


 
 Post subject: Re: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Tue 25 Oct, 2011, 13:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
eugene wrote:
If the weekends last from 22:00 (>=22:00) Friday to 21:59:59 Monday (<22:00) why I haven't got a crossing of MAs? (as I sad Filter.WEEKENDS is used while calculating MA)
For better assistance on this, please provide a code fragment where you call the indicator and process its values.
eugene wrote:
Why the MA's values just after the weekend calculated by API and shown on the chart are different?
Please check if your strategy complies with the following:
https://www.dukascopy.com/wiki/index.php ... _checklist


 
 Post subject: Re: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Tue 25 Oct, 2011, 20:24 

User rating: 0
Joined: Mon 24 Oct, 2011, 14:12
Posts: 5
Location: Russian Federation,
API Support wrote:
For better assistance on this, please provide a code fragment where you call the indicator and process its values.
Please check if your strategy complies with the following:
https://www.dukascopy.com/wiki/index.php ... _checklist

sources are attached.
I've checked all points of checklist. It looks like everything is ok.


Attachments:
StrategyContainer.java [1.78 KiB]
Downloaded 307 times
MAOpen.java [7.55 KiB]
Downloaded 298 times
Tester.java [4.9 KiB]
Downloaded 305 times
CredentialsLoader.java [1.56 KiB]
Downloaded 300 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: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Thu 27 Oct, 2011, 12:34 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
eugene wrote:
which months are used for a winter working time?
GMT does not get affected by daylight saving - so as far as JForex and Filter.WEEKENDS are concerned - the hours are the same regardless of month. Though you have to take into account DST if you need to take into account some particular Market Hours, see:
https://www.babypips.com/school/trading-sessions.html
eugene wrote:
Why the MA's values just after the weekend calculated by API and shown on the chart are different?
We managed to replicate the problem. To be precise, the values are off for the value count after the weekend that matches the MA timePeriod. As a temporary workaround you can consider passing price array to the indicator, see (in your case you would need an array of size timePeriod + 2 and insert there IBar.getClose values of historical bars):
https://www.dukascopy.com/wiki/index.php ... r_on_array


 
 Post subject: Re: Troubles while testing with ITesterClient Post rating: 0   New post Posted: Thu 27 Oct, 2011, 13:16 

User rating: 0
Joined: Mon 24 Oct, 2011, 14:12
Posts: 5
Location: Russian Federation,
Thanks.
Please, let me know when the problem will be fixed. I am looking forward to hearing from you soon


 

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