View Full Version : Discrepencies between backtest and live sim
darckeen
03-02-2009, 09:08 AM
I've been running a live sim overnight with a currency system and I've been getting alot of discrepencies between how the system works in backtest and in live. I have UpdateOnClose = true on the strategy and when going live it trades like it UpdateOnClose = false. Is this because i'm using Close[0] to trigger my signals and should be using Close[1] when going live?
Also whats the deal with whenever I start a strategy the unrealized p/l starts ticking away when the system hasn't entered a trade yet?
NinjaTrader_Josh
03-02-2009, 09:36 AM
darckeen,
If you have CalculateOnBarClose = true it should not run on every tick regardless of you using Close[0] or not. When CalculateOnBarClose = false, Close[0] refers to the last traded price. When it is true, Close[0] refers to the closing price of the bar that has just closed (not the currently building bar).
When you start up your strategy it runs through all the historical data on the chart and determines a virtual strategy position. That is what you are seeing. Please be aware of the difference between a strategy position and an account position. This article outlines the differences: http://www.ninjatrader-support2.com/vb/showthread.php?t=4033
darckeen
03-02-2009, 02:11 PM
Attached is a screen shot of the problem, on the left is a Strategy Analyzer chart of the strategy that is entering the trade as expected. On the right is the live sim of the same strat, it triggers when a new bar opens above the Bollinger Band.
protectedoverridevoid Initialize()
{
CalculateOnBarClose = true;
AccountSize = 100000;
BarsRequired = 14;
EntriesPerDirection = 1;
Add(Bollinger(2,14));
SetProfitTarget(CalculationMode.Percent,.002);
SetStopLoss(CalculationMode.Percent,.002);
}
protectedoverridevoid OnBarUpdate()
{
if (String.Equals(Mode,"Live")) { DefaultQuantity = 1; }
if (String.Equals(Mode,"Backtest")) { DefaultQuantity = 100000; }
if (CrossBelow(High,Bollinger(2,14).Upper,1)) { EnterShort(DefaultQuantity); }
if (CrossAbove(Low,Bollinger(2,14).Lower,1)) { EnterLong(DefaultQuantity); }
}
NinjaTrader_Josh
03-02-2009, 02:27 PM
You sure you had CalculateOnBarClose set to true while running live?
darckeen
03-02-2009, 02:29 PM
Here is a better screen shot of the problem occuring again a few bars later:
NinjaTrader_Josh
03-02-2009, 02:37 PM
Are you absolutely sure it is set to true? If you are, please use TraceOrders = true to debug your orders.
darckeen
03-02-2009, 02:56 PM
I'm using the same exact strategy with the code as shown. Is there anywhere else in the IDE that the CalculateOnBarClose that i'm specifying in the code could be overriden?
Also here is a screenie of another problem I seem to be encountering, double fills.
NinjaTrader_Josh
03-02-2009, 02:59 PM
Overfills are possible depending on your strategy. In a fast moving market, what you see is completely possible.
CalculateOnBarClose is selected when you run your strategy.
darckeen
03-02-2009, 03:38 PM
Could the Bollinger Band being set CalculateOnBarClose = false be causing the problem? I had noticed when looking at the Strategy Analyzer chart window that the Bollinger Band was calculation tick by tick.
NinjaTrader_Josh
03-02-2009, 03:42 PM
In an indicator that is referenced by a strategy there should be no CalculateOnBarClose code line used. If the indicator does have this line please remove it.
darckeen
03-02-2009, 05:50 PM
Uhm, I just realized that there is CalculateOnBarClose in the Strategy Selection addition dialog. Mabey I had that one set to false, would that override the designation made in the code?
NinjaTrader_Bertrand
03-03-2009, 05:58 AM
Yes darckeen, this would override it.
darckeen
03-03-2009, 11:41 AM
Yeah the sim strategy dialog setting was the issue. Eveything working as intended now, thank you for your patience :)