View Full Version : Quick Questions regarding strategy historical processing
bridenour
02-18-2009, 07:59 AM
Hi,
I have a strategy that manages its own ongoing balance (AccountBalance). I set the initial value in the strategy dialog in the beginning, and then the strategy manages the ongoing total based on profit/loss.
When i run this strategy live at the beginning of each day, it goes back and processes a significant amount of historical data and virtual trades (seems like about two weeks worth or more). The end result is that after it processes this historical data, the account balance is very wrong to start the trading day.
I have min bars required set to zero, and i also have the lookback number of minutes set to only 60. For some reason, it still processes a couple of weeks of historical data.
How can i keep the strategy from processing historical trades? I used the (Historical) function, but this will keep any historical data from being processed and will impact the signal generating functions of the strategy.
Any ideas how I can keep my account balance from being updated before the strategy begins to process live orders?
Thanks
NinjaTrader_Josh
02-18-2009, 08:07 AM
You can just let it run and do its thing and then as it goes live, reset the AccountSize value.
if (!Historical && setAccount)
{
AccountSize = 25000;
setAccount = false;
}
bridenour
02-18-2009, 08:11 AM
now that is good thinkin'!
Thanks!
bridenour
02-18-2009, 08:22 AM
So, i think this will fix my core problem and allow the strategy to execute ok.
But, won't this throw off my profit related metrics? For example, i track and report on cumulative profit...since it is processing all these historical trades (virtually), it will think it has amassed this profit prior to ever processing a live order.
is there anything easily done about that? Its not the end of the world, but it would be nice to produce accurate statistics.
Thanks
NinjaTrader_Josh
02-18-2009, 08:28 AM
Not sure what you mean. Profit performance is not influenced at all.
http://www.ninjatrader-support.com/HelpGuideV6/GetProfitLoss.html
http://www.ninjatrader-support.com/HelpGuideV6/Performance.html
http://www.ninjatrader-support.com/HelpGuideV6/TradeClass.html
bridenour
02-18-2009, 09:11 AM
Hi,
I use this statement to add trade profit to my running balance during processing:
Positions[currentStock.GetIndex()].GetProfitLoss(Close[0], PerformanceUnit.Currency)
What I am finding is that when i run the strategy live, it preprocesses a bunch of historical data and runs up the balance prematurely. Is there some way to only take profit/loss from real time trades? Maybe that is my mistake.
thanks
NinjaTrader_Josh
02-18-2009, 09:26 AM
First, remember GetProfitLoss() is unrealized PnL. I recommend you use the Performance class and just aggregate those.
if (Performance.RealtimeTrades.Count > 0)
{
// Get the last completed real-time trade
Trade lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
// Calculate the PnL for the last completed real-time trade
double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;
// Pring the PnL to the Output window
Print("The last trade's profit is " + lastProfit);
}
bridenour
02-18-2009, 09:30 AM
Great, thanks. I will switch to that!
bridenour
02-19-2009, 04:05 PM
Hi Josh,
I switched to this method of profit calculation, but it seems a little flaky.
Basically, I am calling "ExitLong()..."
and then I am generating an email that immediately sends me the P/L based on the code you provided. Unfortunately, it is sending me some numbers that don't correlate to the real P/L of the trade (not even close, really).
Is there any requirement that I must wait until another bar is processed to use this code, or should it work on the same bar immediately after calling ExitLong?
Thanks!
NinjaTrader_Josh
02-19-2009, 04:24 PM
bridenour,
Just because you called ExitLong() does not mean the order was filled by the exchange yet. You need to wait for your order to be filled before you will receive proper values.
bridenour
02-19-2009, 06:00 PM
Ok, thats what i was afraid of. What do you think is a "best practice" for this? Simply wait until the next bar arrives? Or is there a more surefire approach?
NinjaTrader_Josh
02-20-2009, 07:18 AM
If you have the ExitLong() stored to an IOrder you can use OnOrderUpdate() and OnExecution() to track the status of the order. When you receive an order state of Filled then you know you can run your profit checks.
bridenour
02-20-2009, 03:40 PM
Ok i will give that a shot.
one thing i noticed -- when I submit a market order, it is often filled in multiple batched. When i execute your real time trade profit code, it seems like it is only grabbing one of these partial fills, and not the profit for the overall market order. In order words, it seems like each partial fill for a single market order is tracked as an individual real time trade, making it difficult to get an overall P/L for the entire trade.
Does this agree with your understanding?
Thanks
NinjaTrader_Ben
02-22-2009, 11:08 AM
Hello,
I am not sure. I will have someone respond to this post on Monday.
bridenour
02-23-2009, 06:56 AM
I do have the IOrder stored and am using OnExecution. Does a single market order get stored to multiple "trades" (such as each partial fill is stored on a "trade")? If so, is there any way to group them logically to sum up the total P/L?
Thanks!
NinjaTrader_Bertrand
02-23-2009, 07:19 AM
Hi bridenour, please check your settings in the 'Strategies' tab - http://www.ninjatrader-support.com/HelpGuideV6/StrategiesTab.html
Have you set it to 'PerEntryExecution'? If so, please retry with 'ByStrategyPosition'.
You can find more details about the Trade class here - http://www.ninjatrader-support.com/HelpGuideV6/TradeClass.html
bridenour
02-24-2009, 04:54 AM
Ok, i switched it to byStrategyPosition and will see how that affects the "Trade" reporting. It's not completely clear, but does sound like it might then report on the holistic trade.
Thanks for your help...