Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Limited use of variables
Collapse
X
-
code exampe that works
// Condition set 1
if (
Close[0]==Close[0]
)
{
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");
double gh1 =Highs[2][1];
double gh2 =Highs[2][2];
double gh3 =Highs[2][3];
double gh4 =Highs[2][4];
double gh5 =Highs[2][5];
double gh6 =Highs[2][6];
double gh7 =Highs[2][7];
double gh8 =Highs[2][8];
double gh9 =Highs[2][9];
double gh10 =Highs[2][10];
double gh11 =Highs[2][11];
double gh12 =Highs[2][12];
double gh13 =Highs[2][13];
double gh14 =Highs[2][14];
double gh15 =Highs[2][15];
double gh16 =Highs[2][16];
double gh17 =Highs[2][17];
double gh18 =Highs[2][18];
double gh19 =Highs[2][19];
double gh20 =Highs[2][20];
}
exampe that does not work
// Condition set 1
if (
Close[0]==Close[0]
)
{
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");
double gh1 =Highs[2][1];
double gh2 =Highs[2][2];
double gh3 =Highs[2][3];
double gh4 =Highs[2][4];
double gh5 =Highs[2][5];
double gh6 =Highs[2][6];
double gh7 =Highs[2][7];
double gh8 =Highs[2][8];
double gh9 =Highs[2][9];
double gh10 =Highs[2][10];
double gh11 =Highs[2][11];
double gh12 =Highs[2][12];
double gh13 =Highs[2][13];
double gh14 =Highs[2][14];
double gh15 =Highs[2][15];
double gh16 =Highs[2][16];
double gh17 =Highs[2][17];
double gh18 =Highs[2][18];
double gh19 =Highs[2][19];
double gh20 =Highs[2][20];
double gh21 =Highs[2][21];
}
Comment
-
Run time errors of a strategy are generally written to the Log tab of the Control Center window. I suspect in the log tab you have an error that says something like "Index out of range".
The problem is that you are accessing 21 bars back. In a strategy, the default "Minimum bars required" is 20. This means the strategy will not call OnBarUpdate() until 20 bars have been seen. In the case of the second example, you are accessing 21st bar which does not exist.
- You can change the min bars required when running a strategy to 21 or
- Read this post - http://www.ninjatrader-support.com/v...ead.php?t=3170RayNinjaTrader Customer Service
Comment
-
Ok that does make the code work, but it can be a problem on a multi time frame chart if I want to reference a lot of bars on a low time frame chart and a smaller number of bars back on a bigger time frame as a setting to enable the smaller time frame may cause problems with the higher time frame. Is there a way to around this?
Also is it possible to use the LowestBar and HighestBar commands where the reference begins from a point in the past for example if I want to find the highest high for 50 bar bars but starting the search from a bar 100 bars ago instead of the current bar?
Comment
-
I see, there is no way around at this time.
There is no method signature to get the HighestBar but starting x bars back. What you could do to work around this is create an internal IntSeries object (call it highestBarSeries etc...) and on each OnBarUpdate() call store a value such as:
highestBarSeries.Set(HighestBar(High, 50));
Then you could reference this series such as:
Print("The highest high bar of the past 50 bars starting 100 bars ago is " + highestBarSeries[100]);
Something like that in concept.RayNinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment