PDA

View Full Version : NinjaScript Buggy and Inacurate. Please Help !!!


Obi
02-15-2009, 07:08 AM
Hello,

I created a test indicator (accepting the default values of the wizard just to have a bare minimum indicator, in order to debug the odd behavior)

The resulting created indicator code and the test code:

protected override void OnBarUpdate()
{
Print("");

for (int idx =0; idx < 20; idx++)
{
Print("Value before : " + Close[idx]);
}
Print("");

// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Plot0.Set(Close[0]);
}

After loading this to a "3Minutes YM Chart, Connected to simulator", I get the following odd result:

Value before : 10594


1. The print shows only one value (the above value)
2. This value is not even the last value showing on the chart ( 10729 is the last value).
3. 10 minutes, 30 minutes and An hour later, I still get the same single value.

I changed the code to the following:

protected override void OnBarUpdate()
{
Print("Value After : " + Close[0]);
Print("Value After 2: " + Close[1]);
Print("Value After 3: " + Close[2]);
Print("");

for (int idx =0; idx < 20; idx++)
{
Print("Value before : " + Close[idx]);
}
Print("");

// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Plot0.Set(Close[0]);
}

The result (some 10 minutes later):

Value After : 10594


That's it!??? No need to tell you that this is very odd and extremely frustrating.

I desperately need your help and solution to this bug as all my work is currently suspended until this is resolved.

Obi

mrlogik
02-15-2009, 07:32 AM
First, you need to convert the Close[] to a string before you print it out

Close[0].ToString();


Second, you should have the following statement before your for loop.

if(CurrentBar < 20)
return;


The reason for this is you don't want to cause an exception by trying to access data that doesn't yet exist on the chart.

hope this helps

NinjaTrader_Bertrand
02-15-2009, 08:10 AM
Hi Obi, I already responded to your email sent to our support inbox.

Thanks for your input mrlogik.

Obi
02-15-2009, 11:25 AM
Hi NinjaTrader_Bertrand and Mr.Logik,

The following still give the same result as explained earlier:

protected override void OnBarUpdate()
{
Print("Value After : " + Close[0].ToString());
Print("Value After 2: " + Close[1].ToString());
Print("Value After 3: " + Close[2].ToString());
Print("");

// for (int idx =0; idx < 20; idx++)
// {
// Print("Value before : " + Close[idx]);
// }
// Print("");

// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Plot0.Set(Close[0]);
}

Result:

Value After : 10594

As you can see, hours after I reported the issue, I'm still getting the same single value.

Can you please have a look at this. It's blocking everything.

Obi

NinjaTrader_Ray
02-15-2009, 12:07 PM
I did not see that you added this to your code:

if(CurrentBar < 20)
return;

mrlogik
02-15-2009, 08:52 PM
Check the LOG tab as well for errors

Obi
02-16-2009, 06:48 AM
MrLogik, NT_Ray, NT_Bertrand,

Thanks for the tips. The "Bar checking condition" did the trick.

However, now the data get retrieved once (1 call to "getData"). But no runs in the subsequent "OnBarUpdate"s.
Looking in the Log tab, suggested by MrLogik, reveals the following error:

"ERRor on calling the 'OnBarUpdate' method for Indicator 'EJ' on bar 100. Index was outside the bounds of the array."

I understand there is an Array overflow somewhere. When I increase the MAX_DATA to 200, the error persist with 200 instead of 100. There clearly is a relation there.
It seems as if the internal index (iterator) isn't being reset during subsequent calls. Is this correct or am I missing something else?

The 'prints' output stops with the last element of the Array. The last 'print' (with the time) never executes (see below).

protected override void OnBarUpdate()
{
if (CurrentBar < _MAX_DATA_POINTS)
return;

getData( Close );

// EJPlot.Set( _data[ 0, 1] );
for (int idx = 0; idx < _Solutions.Length; idx++)
{
Print("Data Nr." + idx + " : " + _Data[idx, 1].ToString() );
}

Print("<><><> " + DateTime.Now.ToString("HH:mm:ss") + " <><><>");
}

Thanks in advance for your help,
Obi

NinjaTrader_Josh
02-16-2009, 09:14 AM
Obi,

We are not sure what you are doing with these Data[] arrays. You need to check your loop and ensure you do not try to access an invalid index value.

You will need to debug it. Please see this sample on using try-catch blocks: http://www.ninjatrader-support2.com/vb/showthread.php?t=9825