PDA

View Full Version : Different Bar Index between BackTesting and Market Replay


simone
09-27-2007, 02:07 AM
Dear support,
we developed strategy in BackTesting and we noted that index is 0 for current bar, for previus bars is >0 and for next bars is<0. In Market replay we noted that index 0 is null position, to get first bar index is -1 and to get current bar index is -Bars.Count. Is it correct or I am wrong?
My problem is max and min functions, in back testing MAX(High,9)[0] work fine but in Market Replay no, what can I do? We are c# developers and we integrated excel from Ninja script, is there a possibility to manage a form from your script? Our problems are:
1) Initialize function is called one or more times evenif strategy is not used
2) There isn't event to know if the strategy is closed/unload/dispose, so we can't unload all our variables (for example a timer)

Very Thanks for you support

NinjaTrader_Dierk
09-27-2007, 02:44 AM
a) your understanding of the bar indexing is correct. It works the same realtime, historical and in replay mode.
b) NinjaScript consultants are available to help program your custom indicators/strategies or to help our users throughout their learning curve. Additional information is located here - http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm

simone
09-27-2007, 03:49 AM
Thanks,
In my strategy I use MAX(High,9)[0] function.
Activating Market Replay Connection, Chart and my Strategy, I note when strategy process Max function, the following code is not interpreted.

Regards

NinjaTrader_Dierk
09-27-2007, 03:52 AM
Please debug your strategy e.g. by following our educational resource here: http://www.ninjatrader-support.com/vb/showthread.php?t=3418

KBJ
10-01-2007, 03:43 PM
How about adding

if (CurrentBar < 9) return;

before the MAX(High,9)[0] function?

It sounds like this works differently for the Market Replay vs Backtesting. Could the setting of "Min. bars required" be different?

Best regards,

KBJ

simone
10-02-2007, 01:22 PM
Hi,
no Min bars required is the same..
I think I solve the problem, I manage data in a procedure that was call from a timer (not from your OnBarUpdate), so your sistem can't know in this moment which is the effective position (index 0) and MAX or MIN go in error status. I replicate with 2 my functions Get_Max and Get_Min your MAX and MIN and strategy works..
Thanks