PDA

View Full Version : Taking action at the end of a session


bbarroux
10-10-2007, 06:08 AM
Hi,
I'm running a backtest on a strategy with sessions configured from 8AM to 9PM.
I want, at the end of the day, to output a simple report about the day. The point is that I don't know how to do that. Obviously, there is no such thing as a "lastBarOfSession". The dispose method is called at the end of backtest but not at the end of each session.

Outputing in the onbarupdate method, while checking for a specific time won't work, since somedays there is quotations until 6PM while other days will have quotations up to 8PM.

Does anyone have an idea of how I should do.

The only working idea i had so far is to call the output method at each onbarupdate call, each time overwriting the report with the latest values, which is a bit a shame in terms of waste of ressources.

Thanks in advance.

NinjaTrader_Dierk
10-10-2007, 06:33 AM
How about:if (Bars.FirstBarOfSession)
{
// your report logic here
// print report data of previous session
}

bbarroux
10-10-2007, 06:42 AM
Yes, I thought about that one, which would perfectly do the trick in backtesting context.
But when the strategy will be deployed live, I'm not very confortable to have the program waiting for the next morning (or the next monday)to output the report, because it means that ninjatrader (and the computer running it) can never be stopped), which may be an issue.

NinjaTrader_Dierk
10-10-2007, 06:43 AM
For realtime you could add additional logic which triggers at a specific time.

bbarroux
10-10-2007, 07:00 AM
I'm not sure of how i could do this :
If I understand correctly, everything must be anyway triggered from a onbarupdate call.
If the market closes at 6PM, how can i have something triggered at 8PM? If i have a bar period of one minute, will the onbarupdate be called every minute anyway, even if there is no new quotations? In this case, how would the Close[0], High[0],...variables be populated? with the last quotation of the day?
Sorry for insisting on this, your help is very much appreciated.

NinjaTrader_Dierk
10-10-2007, 07:05 AM
How about creating a report at 5:59 PM (last bar before session close)?

If that will not work, then you could schedule a .NET timer which triggers in at 8PM (provided your strategy is running then). Note: This is beyond what we can support.

bbarroux
10-10-2007, 07:16 AM
Thanks Dierk,

the point is that most time the market will close at 8PM, while sometimes it may close before. So i maybe will go for the Timer option (note : and stop bothering you with this :))
The drawback of this is that it prevents from using the exact same program in backtesting and realtime context.

Suggestion : it would be handy to have a callback function when the session ends : an onSessionEnds() method which would be triggered after(or before) NinjaTrader performs the potential exitOnClose actions

Thank you for your help.

NinjaTrader_Dierk
10-10-2007, 07:22 AM
Thanks for your suggestion. We'll add it to the list.