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.

How to use multiple instruments in the same strategy?
 Post subject: How to use multiple instruments in the same strategy? Post rating: 0   New post Posted: Tue 31 Jul, 2012, 08:11 
User avatar

User rating: 0
Joined: Tue 01 May, 2012, 06:37
Posts: 5
Location: Peru, Lima
Greetings, recently i code an strategy that use multiple timeframes and instruments but whats the purpose of use the method setSubscribedInstruments, if the code doesn't respect that statement and open orders with an instrument that isnt subscribed? This doesnt happen on Historical Tester but it happens on Demo mode, even if i subscribe a set of instrument.

If i run a a simple compare like this:

for (Instrument instr2 : subscribedInstruments5){
if (instrument.equals(instr2)){
//some code
}
}

To filter out just the instruments subscribed in subscribedInstruments5
using the follow statements:

subscribedInstruments5.add(Instrument.EURUSD);
subscribedInstruments5.add(Instrument.USDJPY);
subscribedInstruments5.add(Instrument.AUDJPY);
subscribedInstruments5.add(Instrument.AUDNZD);

context.setSubscribedInstruments(subscribedInstruments5);

It doesnt work, also opens positions with instruments that i doesnt even subscribed.

It also happens if i use the method contains like this:

if (selectedInstruments5.contains(instrument))

So is there a way to compare multiple instruments in an strategy?

Thanks for your time, best regards.


 
 Post subject: Re: How to use multiple instruments in the same strategy? Post rating: 0   New post Posted: Tue 31 Jul, 2012, 08:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Andres1 wrote:
the code doesn't respect that statement and open orders with an instrument that isnt subscribed?
Obvioulsy you can't open orders for instruments that are not subscribed, you can find out already subscribed instruments by calling ICotext.getSubscribedInstruments. In work with live data the strategy works with all instruments that are currently subscribed by the platform. IContext.setSubscribedInstruments (use the 2-argument method for synchronous subscription) is for the case when you need to make sure to have the particular instruments subscribed, but it will not remove the instruments that are already subscribed in the platform. Please read our wiki:
https://www.dukascopy.com/wiki/#Subscribe_to_an_instrument


 

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