![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Sep 2007
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
I’ve been trying to use double variables in my code but when I use more than about 20 at once they don’t seem to work. The code will still compile. But they do not seem to get referenced when the code is run.
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Could you provide more specific details since I unfortunately do not follow.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Sep 2007
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
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]; } |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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=3170
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Sep 2007
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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.
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User variables | Bogan7 | Strategy Development | 1 | 01-06-2008 01:07 AM |
| Using output variables within a strategy? | Burga1 | Strategy Development | 15 | 11-17-2007 10:04 PM |
| importing variables from .txt | sandro | Indicator Development | 1 | 05-15-2007 06:59 AM |
| where should variables be declared? | Folls | Indicator Development | 2 | 05-04-2007 11:12 AM |
| Plotting variables | MAX | Indicator Development | 2 | 10-30-2006 10:19 PM |