SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Nov 21, 2018 3:23 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Sep 24, 2012 6:33 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Hello,

I am creating a strategy where I want to check if the 5-tick SMA crosses the 20-tick SMA before entering a long position.

If we define:

SMA sma5 = new SMA(bs5T, 5, BarData.Close);
SMA sma20 = new SMA(bs20T, 20, BarData.Close);

where bs5T and bs20T are the 5 and 20 tick barseries, respectively.

I then want to check:

Cross cross = sma5.CrossesAbove(sma20, bar))
if (cross == CrossAbove)
{
}
before entering a long position. While this syntax is clear (i.e. the CrossAbove method requires a bar to be passed), I want to know if it is possible to have "bar" update at every tick so that my code can evaluate if the cross takes place on every incoming trade rather than just at bar closes.

How can I go about doing this?

My initial thought was to capture the new bar at every tick in the following way:

public override void OnBarOpen(Bar bar)
{
if ((bar.Type == BarType.Tick) && (bar.Size == 5)) bar5T = bar;
if ((bar.Type == BarType.Tick) && (bar.Size == 20)) bar20T = bar;
}

public override void OnTrade(Trade trade)
{
if (bar5T != null) bs5T.Add(bar5T);
if (bar20T != null) bs20T.Add(bar20T);
}

Can someone opine if I am on the right general track? Thank you.


Top
 Profile  
 
PostPosted: Tue Sep 25, 2012 1:36 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
Sorry to say, but FWIW, I don't think you're on the right track because you want to do things and be active on every tick (Trade), but you want to work with data (bars) that are only formed and valid at bar-like intervals when OnBar is active.

If you want to do stuff on every trade, move your logic into OnTrade. If need be, build your own 5 and 20 tick bars yourself in the OnTrade handler, so you can use them there.


Top
 Profile  
 
PostPosted: Tue Sep 25, 2012 4:57 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
thanks. i will try building them manually.


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

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