Array[7] = {1,2,3,4,5,6,7}; // ?
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
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
-
-
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
-
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
-
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
-
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 cre8able, 02-11-2023, 05:43 PM
|
3 responses
236 views
0 likes
|
Last Post
by rhubear
Today, 10:46 AM
|
||
Started by frslvr, 04-11-2024, 07:26 AM
|
8 responses
113 views
1 like
|
Last Post Today, 10:30 AM | ||
Started by stafe, 04-15-2024, 08:34 PM
|
10 responses
45 views
0 likes
|
Last Post
by stafe
Today, 10:29 AM
|
||
Started by rocketman7, Today, 09:41 AM
|
3 responses
11 views
0 likes
|
Last Post Today, 10:07 AM | ||
Started by traderqz, Today, 09:44 AM
|
2 responses
10 views
0 likes
|
Last Post Today, 10:00 AM |
Comment