SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Dec 09, 2019 4:02 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Apr 09, 2014 6:25 pm 
Offline

Joined: Sun Sep 01, 2013 9:31 pm
Posts: 22
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,


Top
 Profile  
 
PostPosted: Wed Apr 09, 2014 6:43 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Hi,

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

Regards,
Anton


Top
 Profile  
 
PostPosted: Thu Apr 10, 2014 7:04 am 
Offline

Joined: Sun Sep 01, 2013 9:31 pm
Posts: 22
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


Top
 Profile  
 
PostPosted: Thu Apr 10, 2014 11:57 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
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


Top
 Profile  
 
PostPosted: Thu Apr 10, 2014 12:03 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group