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.

Stochastic indicator returns zeros
 Post subject: Stochastic indicator returns zeros Post rating: 0   New post Posted: Fri 04 Nov, 2011, 09:33 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
Hello,

I have created a strategy that uses the stochastic indicator. It gets the indicator values in the onBar method filtering by 1 minute period and EURUSD instrument. The indicator works well except that after some hours it begins to return zeros or numbers quite near to zero. This happens for both values returned by the indicator and continues like that until I stop the strategy - e.g. I start the strategy and it works correct for two hours and for the next three hours the indicator returns zeros and I stop the strategy. I've connected using standalone program, not the client. Please, assist me in solving my problem.

Regards,
dspetrov


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Mon 07 Nov, 2011, 09:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
1) Do you run the strategy in live-mode or back-test it?
2) For more efficient assistance, please provide the relevant code fragments.


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Wed 09 Nov, 2011, 13:27 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
It didn't happen again. The only thing that is different now is that I'm using another demo account. I'll provide details in case this start to happen again. Thank you!


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Thu 17 Nov, 2011, 09:33 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
The problem I'm going to state now is not the previous problem in the post, but it is similar so I'll put it here. The stochastic indicator returns for both its values NaN in back-test mode. In live mode it works correct. The value of sma indicator that I put here is a normal number. Here are code segments that I use...
Starting the strategy:
testerClient.setInitialDeposit(Currency.getInstance("USD"), 10000000);
testerClient.setDataInterval(ITesterClient.DataLoadingMethod.DIFFERENT_PRICE_TICKS, fromTimeLong, toTimeLong);
testerClient.startStrategy(strategy);


The onBar method:
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
   if (selectedInstrument.equals(instrument) && period.equals(fixedPeriod)) {
      double[] stochastic = indicators.stoch(instrument, period, side, fastKPeriod, slowKPeriod , slowKMaType, slowDPeriod, slowDMaType, shift );
                double sma = indicators.sma(instrument, period, side, IIndicators.AppliedPrice.MEDIAN_PRICE, 10, 4);
      createOrderOnStochastic(instrument, bidBar, stochastic);
   }
}


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Mon 21 Nov, 2011, 09:36 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We did not manage to reproduce the this. We used the following strategy:
Attachment:
StochTest.java [2.63 KiB]
Downloaded 310 times


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Wed 23 Nov, 2011, 12:24 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
I tested again with your strategy and no defining the test time interval - it worked. I investigated further and it turned out that because my test time interval was 14-25 November 2011 the data contained zeros as if testing on non working days. I checked and it seems that the historical data for 14.11 and until 03:00 on 15.11 is missing. Do you have any idea why?

Starting my tests on other time periods works well. Thank you!


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Wed 23 Nov, 2011, 18:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We managed to receive values over the particular period, find program using IClient (remember to insert your username and password) and adjusted strategy version in attachments.


Attachments:
StochTest3.java [2.64 KiB]
Downloaded 303 times
HistoryIntervalStoch.java [5.18 KiB]
Downloaded 308 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: Stochastic indicator returns zeros Post rating: 0   New post Posted: Thu 24 Nov, 2011, 21:43 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
I checked your code and compared it to mine. Generally it does the same but there's one difference - I don't have the line that sets the cache directory
client.setCacheDirectory(new File("cache_directory_path"));

When I put it my strategy worked well.

Moreover, I did some modifications to your code to test if it will stop working.
1. I removed the line that sets the cache folder. I run the strategy and it worked correctly.
2. In addition to the removed line, I changed the interval to a wider one - not ending 11/15/2011 03:00:00 but 11/16/2011 03:00:00. I run it and for the time until
11/15/2011 01:00:00 the data wasn't correct and for every hourly bar there were exceptions - "java.lang.Exception: Received candle has older time than pervious candle, ignoring"

This looks to me as two possible reasons:
1) If not setting explicitly the cache folder there are problems with wider intervals, so setting the folder is obligatory.
2) There is some bug.

Do you think it's one of these? Or may it be something else?


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Fri 25 Nov, 2011, 18:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
dspetrov wrote:
2. In addition to the removed line, I changed the interval to a wider one - not ending 11/15/2011 03:00:00 but 11/16/2011 03:00:00. I run it and for the time until
11/15/2011 01:00:00 the data wasn't correct and for every hourly bar there were exceptions - "java.lang.Exception: Received candle has older time than pervious candle, ignoring"
Do you mean that you chose the period 11/15/2011 03:00:00 - 11/15/2011 01:00:00? The exception is rather straightforward - the start time is bigger than the end time.
dspetrov wrote:
1) If not setting explicitly the cache folder there are problems with wider intervals, so setting the folder is obligatory.
This is just due to the fact that if there have been some prolonged server down times or price feed problems, they may cause the local cache to be incomplete. If this is the case, then by deleting local cache over the particular period and then running your strategy over the period will force the data to be reloaded from the server - it will become complete. The default location of the cache is System.getProperty("java.io.tmpdir") + "/.cache".


 
 Post subject: Re: Stochastic indicator returns zeros Post rating: 0   New post Posted: Sun 04 Dec, 2011, 11:16 

User rating: 0
Joined: Thu 20 Oct, 2011, 22:57
Posts: 9
Location: BG
API Support wrote:
dspetrov wrote:
2. In addition to the removed line, I changed the interval to a wider one - not ending 11/15/2011 03:00:00 but 11/16/2011 03:00:00. I run it and for the time until
11/15/2011 01:00:00 the data wasn't correct and for every hourly bar there were exceptions - "java.lang.Exception: Received candle has older time than pervious candle, ignoring"
Do you mean that you chose the period 11/15/2011 03:00:00 - 11/15/2011 01:00:00? The exception is rather straightforward - the start time is bigger than the end time.

No, meant changing the end time of the interval so it becomes 11/14/2011 00:00:00 - 11/16/2011 03:00:00.

API Support wrote:
dspetrov wrote:
1) If not setting explicitly the cache folder there are problems with wider intervals, so setting the folder is obligatory.
This is just due to the fact that if there have been some prolonged server down times or price feed problems, they may cause the local cache to be incomplete. If this is the case, then by deleting local cache over the particular period and then running your strategy over the period will force the data to be reloaded from the server - it will become complete. The default location of the cache is System.getProperty("java.io.tmpdir") + "/.cache".

So I'll set the cache folder from now on. If there are problems, I'll delete the data stored in it, to get it retrieved again. This way it should work. Thank you!


 

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