View Full Version : Plot0.Set(Close[0]); vs Plot0.Set(Close[1]);
amedhussaini
07-26-2009, 06:44 AM
I'm very new to Ninjascripting.. encountered a problem in 1 minute of attempting my first script!
Why does
Plot0.Set(Close[0]);
plot a line appopriately but
Plot0.Set(Close[1]);
plot nothing at all? Shouldn't the latter plot a line tracing the previous close?
Thanks!
roonius
07-26-2009, 07:59 AM
I'm very new to Ninjascripting.. encountered a problem in 1 minute of attempting my first script!
Why does
Plot0.Set(Close[0]);
plot a line appopriately but
Plot0.Set(Close[1]);
plot nothing at all? Shouldn't the latter plot a line tracing the previous close?
Thanks!
Add the following line:
if(CurrentBar == 0) return;
amedhussaini
07-26-2009, 08:02 AM
thank you, makes sense. before, it was stuck waiting for the previous bar before drawing everything?
amedhussaini
07-26-2009, 08:06 AM
ACtually, makes me a bit more confused:
This works:
if(CurrentBar == 0) return;
Plot0.Set( Close[1]);
but now this doesn't work:
if(CurrentBar == 0) return;
Plot0.Set( Close[2]);
roonius
07-26-2009, 08:38 AM
ACtually, makes me a bit more confused:
This works:
if(CurrentBar == 0) return;
Plot0.Set( Close[1]);
but now this doesn't work:
if(CurrentBar == 0) return;
Plot0.Set( Close[2]);
try
if (CurrentBar < 2) return;
you have to make sure you have enough bars before referencing them
amedhussaini
07-26-2009, 08:42 AM
i think i get it now..
whenever i reference a set number of bars in the past, i have to make sure that i stop trying to calculate it if there aren't enough bars left on the chart before i get to bar[0]...
otherwise it will hang.. and continually wait for a new bar
roonius
07-26-2009, 08:47 AM
i think i get it now..
whenever i reference a set number of bars in the past, i have to make sure that i stop trying to calculate it if there aren't enough bars left on the chart before i get to bar[0]...
otherwise it will hang.. and continually wait for a new bar
Calculation starts from the very first bar on your chart (leftmost).
If the bar is first on chart, you are trying to access the bar before it which does not exist.
amedhussaini
07-26-2009, 10:02 AM
thanks, makes even more sense now that i'm looking at it starting left to right