Profile Picture

Live Trading Daily data and NewBar called at midnight

Posted By smersh 4 Years Ago
Posted Wednesday August 13 2014
I'm writing a daily system for the first time. For years I've always worked with minute data and trading logic done in NewTick()...

I'd like to submit orders 30min before a market opens at say 7:30am.

I have only daily data and I notice that NewBar() is called at midnight. Which is way too early for me to be placing orders.

Normally in backtest (and live trading) I'd backtest on tick data and in NewTick() I'd watch the time of day and submit orders when required. In live trading I could also use a timer to call my logic.

However, in backtest, when setting Tick Level Simulation = true, NewTick() also gets called at midnight, so I can't call my logic at an appropriate time of day.

Worse still NewBar is called on midnight Tuesday, Wednesday, Thursday, Friday and Saturday...which means I'd have to send orders Saturday midnight and have hem retained with broker or on exchange over the weekend....Not something I want to do.

Am I missing something, doing something wrong or is there a sensible way to trade daily data both live and in backtest

Perhaps one could inject fake ticks throughout the backtest so the logic can be called intra-bar.....


Posted Wednesday August 13 2014
Use CreateBarsFromTicks = true in your system startup rather than setting the tick level simulation.

Also, see the following for delaying orders for the live aspect of your system:

You will need to execute the live orders by checking against the tick time and executing the delayed orders when you want.

The code will need to follow 2 separate paths to prevent the orders from sitting on the exchange. It is still straightforward to implement.

Posted Wednesday August 13 2014
Thanks for the reply Duane.

How does CreateBarsFromTicks work if I only have daily bar data?

Also the code you reference relies on there being ticks or bars at a higher granularity than daily...

Edited: Wednesday August 13 2014 by smersh
Posted Wednesday August 13 2014
CreateBarsFromTicks breaks the bar into O,H,L,C ticks.

The granularity is based on the data that you are using. Both NewBar and NewTick will be hit. For daily bar data at most you can derive 4 unique ticks. For live data, you can utilize the fact that there is an almost continuous stream on new ticks to place the order at the time you want it to be placed. If you need higher granularity for your backtesting, you will need to obtain higher frequency data (which in many cases is not available).
Posted Wednesday August 13 2014
A bit weird.. you say CreateBarsfromTicks when it looks like you get ticks from bars?Crazy
Posted Wednesday August 13 2014
you are correct. typo.
Posted Wednesday August 13 2014
In my scenario I'll be placing orders before the open so the will be no continuous stream of ticks at that time...

The Daily data I'm using is CSI data and is only updated daily.

So looks like I'm pretty stuck Sad
Posted Friday August 15 2014
Do you have a live data service set up for this? RightEdge won't even submit orders to the live broker unless it's running in live mode, which means you would need a live data service.

I think the way to do this may be to set up a live data service which just sends CurrentTime ticks instead of price data. Then the system can run on your historical EOD data. NewBar() will be called at midnight simulation time, and the system can save the orders that it wants to submit before the market opens. Then it will switch to live mode and the time ticks will start coming in, and when it gets to the right time the system can submit the orders that it calculated during NewBar().

The DelayedOpenPosition logic that Duane linked to is pretty close to what you would want.

Posted Sunday August 17 2014
Hi Daniel,

I have a live market data service and a broker service when live. So I'll be getting trade ticks but not before the market is open.

Can't I just run my strategy logic on a timer instead of the time ticks as you suggest?

If this is correct then my live trading problems are solved.

However I still have the problem in backtest that NewBar() is fired at midnight on Tues, Wed, Thur, Friday and Saturday
Posted Monday August 18 2014
I'd suggest modifying your live broker so that it generates CurrentTime ticks before the market opens. Then you should be able to check the current time in the system NewTick method and submit your order when the right time arrives.

You could also use some sort of timer. The timer will probably raise its event on a different thread so you will need to use SystemData.SynchronizationContext.BeginInvoke() to switch to the system thread before doing anything.

What's the problem with NewBar() happening at midnight during simulation? What time would you like it to happen, and how would that make the system behave differently?


Similar Topics

Reading This Topic

2005-2018 © RightEdge Systems