Array[7] = {1,2,3,4,5,6,7}; // ?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Arrays in NT
Collapse
X
-
Arrays in NT
Sorry for such a basic question but how do I assign values to an an array?
Array[7] = {1,2,3,4,5,6,7}; // ?Tags: None
-
-
Your question, given the example that you show is unclear. Are you asking how to declare an Array?Originally posted by GKonheiser View PostSorry for such a basic question but how do I assign values to an an array?
Array[7] = {1,2,3,4,5,6,7}; // ?
Comment
-
I have an array,
double[] levels = new double[7] {w1,w2,w3,w4,w5,w6,w7};
What I'm trying to do is search the array and find the next highest and lowest number to Close[0] but I cant get the syntax correct, I have:-
hLevel = Array.Find(levels, x > Close[0]);
lLevel = Array.Find(levels, x < Close[0]);
could you tell me what the correct syntax is for this?
Comment
-
GKonheiser,
Take a look at the link below, it should shed more light on the subject -
http://www.dotnetperls.com/array-findCal H.NinjaTrader Customer Service
Comment
-
One way would be to sort the array, then loop through it to find the values that span Close[0] value where you seek.Originally posted by GKonheiser View PostI have an array,
double[] levels = new double[7] {w1,w2,w3,w4,w5,w6,w7};
What I'm trying to do is search the array and find the next highest and lowest number to Close[0] but I cant get the syntax correct, I have:-
hLevel = Array.Find(levels, x > Close[0]);
lLevel = Array.Find(levels, x < Close[0]);
could you tell me what the correct syntax is for this?
Comment
-
Ive now got the array declared but when i try to get the value in the array they come back as null even thou I have populated the array,
this is the code i have so far:-
if(BarsInProgress == dBIP) // Day Bars
{
// Calculate Pivot Points(for order Entery)
pp = Math.Round((Highs[dBIP][0] + Lows[dBIP][0] + Closes[dBIP][0])/3,2);
r1 = Math.Round((2 * pp) - Lows[dBIP][0],2);
s1 = Math.Round((2 * pp) - Highs[dBIP][0],2);
r2 = Math.Round(pp + (Highs[dBIP][0] - Lows[dBIP][0]),2);
s2 = Math.Round(pp - (Highs[dBIP][0] - Lows[dBIP][0]),2);
r3 = Math.Round(r1 + (Highs[dBIP][0] - Lows[dBIP][0]),2);
s3 = Math.Round(s1 - (Highs[dBIP][0] - Lows[dBIP][0]),2);
double[] pivots = new double[7] {r3, r2, r1, pp, s1, s2, s3};
Array.Sort (pivots);
}
if(BarsInProgress == mBIP)
{
int h = Array.BinarySearch(pivots, Close[mBIP]);
if( pivots[0] != 0 || pivots[1] != 0 || pivots[2] != 0 || pivots[3] != 0 || pivots[4] != 0 || pivots[5] != 0 || pivots[6] != 0 )
{
hPiv = pivots[h+1];
lPiv = pivots[h-1];
}
Comment
-
I need to define the array in OnBarUpdate in Daily bars as I am calculating levels on a daily basis and then using the array on a minute time frame?
Comment
-
As there are parts of your code missing I can't say for sure but at first glance I saw
double[] pivots = new double[7] {r3, r2, r1, pp, s1, s2, s3};
was defined inside of one if statement
In the later if statement you check pivots[0] != 0
These won't be referring to each other if that is what you're trying to do. Sorry if I misunderstand.LanceNinjaTrader Customer Service
Comment
-
No you do not. Define it as a class variable and populate it in OBU. Your problem is coming from a scope limitation.Originally posted by GKonheiser View PostI need to define the array in OnBarUpdate in Daily bars as I am calculating levels on a daily basis and then using the array on a minute time frame?
Also, by the very way that you have defined the pivots array, it is already sorted from high to low, so you do not need to run a sort routine in this particular case.
Comment
-
-
Error comparing doubles
Hi
So I have defined and populated my array with doubles (pivot points). I am then using:
i = Array.BinarySearch(pivots, Closes[mBIP]);
to compare Closes to the array but I get an error "**NT** Error on calling 'OnBarUpdate' method for strategy 'PivShortCode/b11fc6d627cb43aaab280f46194ae269': Failed to compare two elements in the array."
When i debug this in VStudio, and look at the error its telling me {"Object must be of type Double."}??
Both Closes[mBIP] and all elements in pivots are doubles.
can anyone shed light on why this is, do I need to convert Closes in some way?
Comment
-
What type is "i" ?Originally posted by GKonheiser View PostHi
So I have defined and populated my array with doubles (pivot points). I am then using:
i = Array.BinarySearch(pivots, Closes[mBIP]);
to compare Closes to the array but I get an error "**NT** Error on calling 'OnBarUpdate' method for strategy 'PivShortCode/b11fc6d627cb43aaab280f46194ae269': Failed to compare two elements in the array."
When i debug this in VStudio, and look at the error its telling me {"Object must be of type Double."}??
Both Closes[mBIP] and all elements in pivots are doubles.
can anyone shed light on why this is, do I need to convert Closes in some way?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment