SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Sep 18, 2019 12:42 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Jan 07, 2008 12:35 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
The code below shows how to access series of 1 and 5 minute bars in a strategy. It's assumed that you have 1 and 5 min bars added to the market data folder of your strategy.

The code also shows how to filter bars coming into OnBar event handler using bar.Size property.

Code:
   public override void OnBar(Bar bar)
   {
      BarSeries bars1min = GetBars(60);
      BarSeries bars5min = GetBars(300);
      
      if (bar.Size == 300)
      {
         if (bar.Close > bars1min.Ago(2).Close)
             Buy(100);
      }
   }


Top
 Profile  
 
PostPosted: Mon Jan 07, 2008 11:33 pm 
Offline

Joined: Wed Jan 02, 2008 5:39 am
Posts: 23
Hi Dr. Anton:

How do I access series of daily and weekly bars? Should I put use

Code:
BarSeries bars1day = GetBars(23400); // for 6.5hous trading day

or
Code:
BarSeries bars1day = GetBars(86400); // for 24 hours for the day.


Also, how do I get what was the lowest Low since the Buy signal?
How do I get what was the lowest low since trading started at 9:30 AM EST?
How do I set the chart to ONLY collect and show data for 9:30AM EST to 4:00PM EST, instead of showing GMT time when download historical data from IB?

Thanks,

gundam
Dr. Anton Fokin wrote:
The code below shows how to access series of 1 and 5 minute bars in a strategy. It's assumed that you have 1 and 5 min bars added to the market data folder of your strategy.

The code also shows how to filter bars coming into OnBar event handler using bar.Size property.

Code:
   public override void OnBar(Bar bar)
   {
      BarSeries bars1min = GetBars(60);
      BarSeries bars5min = GetBars(300);
      
      if (bar.Size == 300)
      {
         if (bar.Close > bars1min.Ago(2).Close)
             Buy(100);
      }
   }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 5:21 pm 
Offline

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

this depends on the size of bars you have in your "daily" and "weekly" series.

When you run an OQ strategy, the data manager creates one bar series per bar size. Bar size in GetBars(size) should be the same as bar size in your historical data base (and strategy market data folder).

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 5:25 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
BarSeries.LowestLow() method has several overloads

Name Description
LowestLow Gets the lowest Low of bars in this series
LowestLow (DateTime, DateTime) Gets the lowest Low of the bars between specfied dates in this series
LowestLow (Int32) Gets the lowest Low of last N bars in this series
LowestLow (Int32, Int32) Gets the lowest Low of the bars between specfied indicies in this series


You can select one that suits your task. If you know DateTime of your entry order, then

LowestLow (DateTime, Clock.Now)

should work for you.

Regards,
Anton


Top
 Profile  
 
PostPosted: Fri Mar 28, 2008 11:01 pm 
Offline

Joined: Mon Jan 07, 2008 6:18 am
Posts: 58
Dr. Anton Fokin wrote:
The code below shows how to access series of 1 and 5 minute bars in a strategy. It's assumed that you have 1 and 5 min bars added to the market data folder of your strategy.

The code also shows how to filter bars coming into OnBar event handler using bar.Size property.

Code:
   public override void OnBar(Bar bar)
   {
      BarSeries bars1min = GetBars(60);
      BarSeries bars5min = GetBars(300);
      
      if (bar.Size == 300)
      {
         if (bar.Close > bars1min.Ago(2).Close)
             Buy(100);
      }
   }





How would you use the bar.Size property for a n volume or n tick bar?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 1:35 pm 
Offline

Joined: Thu Jan 31, 2008 11:39 am
Posts: 166
Let's assume we have 2 Strategies in 1 Solution. The first uses 5 Second bars, the second 10 Minute bars.

How can I tell the Indicators in the second solution, that they should only use the 10 Minute Bars for calculation and vice versa?

By now, it seems that they are using the 5 second bars as input as well. That leads to the question, why is the MarketData input in the Solution level and not in the Strategy level.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 6:00 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

You can specify exact series you want to use for indicator like
Code:
SMA sma = new SMA(OpenQuant.Bars[BarType.Time, 600], 14);
for 10 min bars.

Regards,
Sergey.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 6:29 pm 
Offline

Joined: Thu Jan 31, 2008 11:39 am
Posts: 166
many thx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 6:51 pm 
Offline

Joined: Thu Jan 31, 2008 11:39 am
Posts: 166
Hm somehow it does not work. The error message says that maybe an assembly reference is missing ("OpenQuant doest no contain the namespace Bars"). I tried it first with:

lri = new LRI(OpenQuant.Bars[BarType.Time, 600],14,Color.Yellow);

then I noticed that OpenQuant.Bars[ needs also the instrument as (first) parameter, so I tried:

lri = new LRI(OpenQuant.Bars[this.Instrument,BarType.Time, 600],14,Color.Yellow);

Same result.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 11:01 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
I think he ment DataManager.Bars[]

though you can simply use

GetBars(BarType.Time, 600);

method of the Strategy class.

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 11:05 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Code:
SMA sma = new SMA(GetBars(600),  14);


Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 11:35 am 
Offline

Joined: Thu Jan 31, 2008 11:39 am
Posts: 166
[I changed the order of the projects within the solution explorer. The Strategy with the 10 minute bars is now the first one from above. I also changed the Bar Lenght of the other Strategy. It is now 1 Minute. Maybe this is important.]

The hint you gave me does not completely work. The indicators of the first strategy are now using the 10 min Bars, which is correct. But now the Indicator of the other Strategy uses also 10 min Bars, but it should be the 1 Min Bars.

To be absolutely sure: The following lines should be in the 'OnStrategyStart' Event code, right?
Code:
indSma = new SMA(GetBars(60),sma);
      Draw(indSma,0);


Also, when I open the Chart for the 1Min Strat (via Rightclick on the Instrument in the project explorer), it shows me the 10Min Chart. So it seems that the second Strategy gets the wrong Bar input.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 1:17 pm 
Offline

Joined: Thu Jan 31, 2008 11:39 am
Posts: 166
Sorry, it seems that the SMA for the 1 minute Strategy is calculated correctly. I was confused by the chart, because it displays the 10minute Bars. Is it possible to have the charts displayed correctly according to the Bars the strategy uses?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 1:40 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Well, the strategy uses both series (i.e. OnBar() will be called for both bar sized). One of this series is default series, Strategy.Bars . This series is drawn by default on the bar chart. You can switch between series in the dropdown list in the OpenQuant main menu.

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2008 2:08 pm 
Offline

Joined: Wed Jan 09, 2008 12:19 pm
Posts: 49
Hi,

If I have a strategy that applys to 1min and 2 min timeframe, how do I handle both 1 min and 2 min exit in OnPositionOpend() { }?
Thanks !


Last edited by octrout on Thu Nov 20, 2008 10:43 pm, edited 1 time in total.

Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group