SmartQuant Discussion

Intrabar Updating of CrossAbove
Page 1 of 1

Author:  ivb73077 [ Mon Sep 24, 2012 6:33 pm ]
Post subject:  Intrabar Updating of CrossAbove


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.

Author:  kkkwj [ Tue Sep 25, 2012 1:36 am ]
Post subject:  Re: Intrabar Updating of CrossAbove

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.

Author:  ivb73077 [ Tue Sep 25, 2012 4:57 pm ]
Post subject:  Re: Intrabar Updating of CrossAbove

thanks. i will try building them manually.

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group