SmartQuant Discussion
http://www.smartquant.com/forums/

Accessing Multiple instruments in one strategy
http://www.smartquant.com/forums/viewtopic.php?f=41&t=10706
Page 1 of 1

Author:  Wajeeha [ Wed Apr 09, 2014 6:25 pm ]
Post subject:  Accessing Multiple instruments in one strategy

Hello Support,

I need to access multiple instrument in a single strategy. I used following lines of code to subscribe instrument programmatically

Code:
public override void OnStrategyStart()
{
   instrument1 = InstrumentManager.Instruments["$GBPUSD"];
}


The problem I am facing is that the bar data i.e. Datetime,OHLC I get from this instrument remains same throughout the strategy. Below is my strategy code:

Code:
using System;
using System.Drawing;

using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyStrategy : Strategy
{
   Instrument instrument1 = null;
   
   public override void OnStrategyStart()
   {
      instrument1 = InstrumentManager.Instruments["$GBPUSD"];
   }

   public override void OnBar(Bar bar)
   {
      Console.WriteLine("Primary instrument = " + Instrument.Symbol + " | Datetime = " + Instrument.Bar.DateTime
         + " | Open = " + Instrument.Bar.Open + " | High = " + Instrument.Bar.High + " | Low = " + Instrument.Bar.Low
         + " | Close = " + Instrument.Bar.Close);
      
      if (instrument1 != null)
      {
         Console.WriteLine("Second Instrument = " + instrument1.Symbol + "DateTime  = " + instrument1.Bar.DateTime
            + " | Open = " + instrument1.Bar.Open + " | High = " + instrument1.Bar.High
            + " | Low = " + instrument1.Bar.Low + " | Close = " + instrument1.Bar.Close);
      }
   }
}


Please advise how can we access different instruments data in a strategy.

Thanks,

Author:  Dr. Anton Fokin [ Wed Apr 09, 2014 6:43 pm ]
Post subject:  Re: Accessing Multiple instruments in one strategy

Hi,

do you have this instrument within the list of strategy instruments?

Regards,
Anton

Author:  Wajeeha [ Thu Apr 10, 2014 7:04 am ]
Post subject:  Re: Accessing Multiple instruments in one strategy

No, Because I don't want multiple instances of the strategy i.e. one for each instrument. I need only one strategy instance in which I want different other instruments data along with base instrument.

Thanks,
Wajeeha

Author:  Dr. Anton Fokin [ Thu Apr 10, 2014 11:57 am ]
Post subject:  Re: Accessing Multiple instruments in one strategy

Hi,

strategy sends market data subscriptions for its instruments, configures market data simulator, etc., so that you should add an instrument to the list of strategy instruments to subscribe this instrument for market data and receive updates.

I understand you don't want to trade this instrument. I suggest you add this instrument to the list of strategy instruments, but also add something like

OnBar()
{
if (Instrument = nontradable_instrument)
return;

.....
}

to every strategy event handler that produces trading signals, etc. to avoid trading with this instrument strategy instance.

Regards,
Anton

Author:  Dr. Anton Fokin [ Thu Apr 10, 2014 12:03 pm ]
Post subject:  Re: Accessing Multiple instruments in one strategy

PS. OpenQuant 2014 is more flexible in this respect and offers several strategy templates, including the one that doesn't create strategy instance per instrument but processes events for all instruments in one instance / event handler, i.e. OnBar(bar, instrument). You are welcome to play with OQ 2014 to see if it fits your needs better.

Regards,
Anton

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/