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.

Accessing indicators in SDK without running a strategy???
 Post subject: Accessing indicators in SDK without running a strategy??? Post rating: 0   New post Posted: Mon 28 Jan, 2013, 18:56 

User rating: 0
Joined: Mon 28 Jan, 2013, 15:30
Posts: 6
Location: SwitzerlandSwitzerland
Dear support

I followed the SDK tutorial at:
https://dukascopy.com/wiki/#JForex_SDK
and tried most of the examples there. So far so good - I understood them.

The only thing I can't figure out is how to access the indicator calculations from outside of a strategy.

From inside a strategy one can call something like:
IIndicators indicators = context.getIndictors();
double [] macdValue = indicators.macd(myCurrencyPair, myBarPeriod, OfferSide.BID, AppliedPrice.CLOSE,12,26,9,0);

BUT how can I call indicator methods before or without starting a strategy at all?
I am attaching a sample code with the method in question on line #30.

Thank you in advance for every hint!


Attachments:
File comment: The question is on line 30.
SdkIndicator.java [3.45 KiB]
Downloaded 375 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: Accessing indicators in SDK without running a strategy??? Post rating: 0   New post Posted: Tue 29 Jan, 2013, 09:59 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
In either case you need to get the implementation of IIndicators, which you can get from the IContext in the IStrategy.onStart. Consider doing something like this:
// start the strategy
LOGGER.info("Starting strategy");
client.startStrategy(new EmptyStrategy() {
   @Override
   public void onStart(IContext context) throws JFException {
      indicators = context.getIndicators();
   }
});
//the startegy has been started in another thread, thus the onStart has not been called at this point yet

//wait max
i = 5;
while (indicators == null && i > 0) {
   Thread.sleep(1000);
   i--;
}

double prevSma = indicators.sma(Instrument.EURUSD, Period.ONE_MIN, OfferSide.BID, AppliedPrice.CLOSE, 10, 1);
System.out.format("last sma: %.5f", prevSma);
System.exit(0);


Attachments:
MainCalcInd.java [5.84 KiB]
Downloaded 385 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: Accessing indicators in SDK without running a strategy??? Post rating: 0   New post Posted: Tue 29 Jan, 2013, 22:31 

User rating: 0
Joined: Mon 28 Jan, 2013, 15:30
Posts: 6
Location: SwitzerlandSwitzerland
Thank you very much - this is exactly what I needed!


 

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