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.

MA produces NaN with custom periods
 Post subject: MA produces NaN with custom periods Post rating: 0   New post Posted: Mon 28 Feb, 2011, 10:43 

User rating: 0
Joined: Thu 10 Feb, 2011, 12:57
Posts: 2
Passing a custom period as parameter in a moving average indicators makes the indicator to return NaN (see sample code). In case the custom period is identical to a built-in period ie ( 1min, 5min) it does return meaningful results.

To reproduce the behavior run the attached code as is and then change the following line:

customTimeframe= Period.createCustomPeriod(Unit.Minute,1);
...works OK

to
customTimeframe= Period.createCustomPeriod(Unit.Minute,2);
..does NOT work

and to
customTimeframe= Period.createCustomPeriod(Unit.Minute,5);
...works OK


Attachments:
Strategy.java [1.31 KiB]
Downloaded 331 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: JFOREX-2789 MA produces NaN with custom periods Post rating: 0   New post Posted: Mon 28 Feb, 2011, 16:03 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Strategy won't receive in progress candles for custom periods unless you subscribe to them manually.
Use the following code to subscribe your strategy to custom period in progress candles:
import com.dukascopy.api.listener.IBarFeedListener;
...
public void onStart(IContext context) throws JFException {
...
  customTimeframe= Period.createCustomPeriod(Unit.Minute,2);
     
        this.context.subscribeToBarsFeed(
            Instrument.EURUSD, customTimeframe, OfferSide.BID, new IBarFeedListener() {
                 public void onBar(
                    Instrument instrument,
                    Period period,
                    OfferSide offerSide,
                    IBar bar
                 ) {
             
                 }
            }
        );           
}


 

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