Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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 GLFX005, Today, 03:23 AM
|
0 responses
1 view
0 likes
|
Last Post
by GLFX005
Today, 03:23 AM
|
||
Started by XXtrader, Yesterday, 11:30 PM
|
2 responses
11 views
0 likes
|
Last Post
by XXtrader
Today, 03:07 AM
|
||
Started by Waxavi, Today, 02:10 AM
|
0 responses
6 views
0 likes
|
Last Post
by Waxavi
Today, 02:10 AM
|
||
Started by TradeForge, Today, 02:09 AM
|
0 responses
14 views
0 likes
|
Last Post
by TradeForge
Today, 02:09 AM
|
||
Started by Waxavi, Today, 02:00 AM
|
0 responses
3 views
0 likes
|
Last Post
by Waxavi
Today, 02:00 AM
|
Comment