View Full Version : Problem with "Closes"
bluelou
08-03-2010, 12:57 PM
I'm getting an an OnBarUpdate() error - Index out of range (see attachment) when I use "Closes" to reference the close of a bar from BarsArray[1]. I'm using NT7 and the error only appears when attempting to trade live. There's no problem with the code when backtesting with StrategyAnalyzer.
(Closes[0][0] >= Closes[1][0]) && (Closes[1][0] >= Closes[1][1])
What can be done to fix this? I don't see any reason why this statement would work in StrategyAnalyzer but not in live trading.
NinjaTrader_Austin
08-03-2010, 01:07 PM
bluelou, are you returning out of OnBarUpdate() if there aren't enough bars (if(CurrentBar < 2) return;)?
There are actually a few different ways for that error message to be called, so that might not be it. Could you post the complete code you're using?
bluelou
08-03-2010, 05:23 PM
Austin,
I'm not sure what you're asking me. What I can tell you is that my code runs live if I exclude the following statement:
(Closes[0][0] >= Closes[1][0]) && (Closes[1][0] >= Closes[1][1])
But, if I include the above statement then I get the OnBarUpdate error that I mentioned. Also, I don't get the error when backtesting. I only get it when trying to run the strategy live.
I'm guessing what you mean is that since I'm referencing Closes[x][1], that is, 1 bar ago. Then for both BarsArray I should begin the statement with if(CurrentBar <2)... to accommodate cases where there are < 2 bars. Is that what you're saying?
NinjaTrader_Austin
08-03-2010, 06:25 PM
bluelou, yes that is what I'm saying - sorry, I could've been more clear. Depending on the timeframe of the secondary bar series, you may need more than two bars, but if both series have the same timeframe, then you'll only have to check for two bars. The code for that is as follows:
protected override void OnBarUpdate()
{
if (CurrentBar < 2)
return;
// rest of your strategy calculations here, including the BarsInProgress checks
}
bluelou
08-03-2010, 08:45 PM
Austin,
What you're saying makes sense to me but I have one question: why did such a simple error make it past the compiler? I have this bug and probably 3 or 4 others that I haven't found yet that don't appear in a backtest using StrategyAnalyzer but do appear as soon as I try to run the strategy live.
This rarely happened with NT6.5 but it seems to be a regular event with NT7. The fact that the code is compiling and running in StrategyAnalyzer but not running live is very frustrating. I've spent 2 days (and probably have 2-3 more days to go) using Visual Studio to debug NinjaScript because the Ninja compiler isn't doing its job.
NinjaTrader_Austin
08-04-2010, 08:09 AM
bluelou, the strategy should run the same on backtesting and live testing. Would you mind sharing the code? I would like to test this out on my computer because the behavior you're reporting should not be happening as a strategy doesn't know whether it is being backtested or running live.
bluelou
08-04-2010, 08:17 AM
Austin,
Give me a day or so since I'd need to write a version of the strategy w/o certain DLL references. Worth noting is that even when I've commented out the DLL calls the difference b/t the backtests and live errors has persisted.
NinjaTrader_Austin
08-04-2010, 08:40 AM
Thank you, your time and assistance is very appreciated.
bluelou
08-04-2010, 12:54 PM
Austin,
Is it possible for you to do some type of remote assistance where you log into my PC (I have LogMeIn)? That way I can show you the several instances where the compiler isn't catching errors w/o having to send you proprietary DLLs and other code. I'm having a few other problems with NT7 also, but the compiler problems are the most serious since I'm unable to trade live until I find a work-around to the compiler problems. Please send me a private message to discuss.
Thx,
Lou
NinjaTrader_Austin
08-04-2010, 04:12 PM
Hi Lou, here are the links I was talking about:
Using OnOrderUpdate() and OnExecution() methods to submit protective orders (http://www.ninjatrader-support.com/vb/showthread.php?t=7499)
Using StreamWriter to write to a text file (http://www.ninjatrader-support.com/vb/showthread.php?t=3475)
Debugging your NinjaScript Code (http://www.ninjatrader-support.com/vb/showthread.php?t=3418)
TraceOrders (http://www.ninjatrader-support.com/vb/showthread.php?t=3627)
bluelou
08-04-2010, 04:15 PM
Austin,
Thx for this. I'll check out these links.
-Lou
bluelou
08-05-2010, 01:57 PM
Austin,
The changes that were made yesterday to correct the Closes[x][y] issue and other issues are no longer persisting in live trading. I'm back to where I started since the strategy won't run live and the live output window are both different from the StrategyAnalyzer output which runs properly. I've also sent you a p.m. I'm looking forward to your response.
Thx,
Lou
NinjaTrader_Josh
08-05-2010, 03:12 PM
Lou,
Austin will be in on Saturday. If you posted what you PMed Austin here directly we could see if we can help out till then. Thank you for your patience.
bluelou
08-05-2010, 03:14 PM
I'm unable to trade a strategy live and the problem I'm having can only be tested while the FX markets are open. I'll send you a p.m. regarding the problem.
bluelou
08-05-2010, 03:28 PM
Josh,
It appears that you have your p.m. shut off. Austin had first taken a look at this yesterday but we never really delved into it because I thought the problem had somehow fixed itself. That's not the case.
I've worked all day today trying to recreate the success of the one successful live test from yesterday before requesting remote assistance but I'm not making any progress. I would really appreciate you taking time to look at this issue on my PC.
As it stands, my strategy runs perfectly fine with StrategyAnalyzer but when attempting to trade live the indicator outputs = 0 in the Output Window. No errors are being thrown in the NT logger and I can't find anything wrong using the Visual Studio debugger. Without any known bugs to resolve I have no idea what the problem is.
Please let me know when you might be available.
-Lou
NinjaTrader_Josh
08-05-2010, 04:39 PM
Lou,
Please send in an email to support [at] ninjatrader [dot] com with a link to this thread and Attn: Josh in the subject. Please include your phone number and I will arrange for the proper resources to assist you tomorrow. Thank you.
bluelou
08-05-2010, 05:05 PM
Josh,
I've sent the email to your attention. I look forward to hearing from you soon.
-Lou
NinjaTrader_Bertrand
08-06-2010, 08:32 AM
bluelou, thank - we got your email and followed up directly to schedule a call.
bluelou
08-06-2010, 08:33 AM
bluelou, thank - we got your email and followed up directly to schedule a call.
I just heard back from Brett a few minutes ago. Thx.
bluelou
08-06-2010, 01:42 PM
In NT6.5, what would be the equivalent to the NT7 code below? (Noting that CurrentBars[x] doesn't exist in NT6.5)
Here's an example using NT7:
if (BarsInProgress == 0)
{
if(CurrentBars[1] >=2)
{if(Closes[1][0] >= Closes[1][1])
{
Cls1up =1;
}
else
Cls1up =0;
}
}
NinjaTrader_Josh
08-06-2010, 02:25 PM
There is no equivalent. You would just have to make and store your own variables that tracks CurrentBars of your various BIPs.
if (BarsInProgress == 0)
CurrentBarsZero = CurrentBar;
else if (BarsInProgress == 1)
CurrentBarsOne = CurrentBar;
bluelou
08-10-2010, 10:12 AM
Brett,
Any progress on the BarsArray issue with Gain Capital data? Is this a bug in the NT7 platform as you had speculated? If so, will the bug be fixed in the next beta, NT7 v20?
Also, I tried your suggestion (sent via Skype IM) to set CurrentBars[1] >= 20 but that just gave me an OnBarUpdate() error "You are accessing an index with a value that is invalid since its out of range."
See attachment for the code that I used.
Thx,
Lou
NinjaTrader_Austin
08-10-2010, 01:14 PM
Lou, I will ask Brett if he has found anything. In the mean time, please try the other code with:
OnBarUpdate()
{
if (CurrentBar < 20)
return;
else
{
// all your other code goes here, starting with
if (BarsInProgress == 0)
...
}
}