Thanks sefstrat!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Matrix with Ninja trader
Collapse
X
-
Hi mrlogik,
Thank you for the example, it's exactly what I was looking for!
When I tried to apply the concept to NT though, I got stuck again!
Assuming I'm working with Primary and Secondary Bars (to securities, BarsArray[0], BarsArray[1]), could you please show how I can build the matrix?
I don't understand how to go from:
sMatrix[0,0] = 1;
sMatrix[0,1] = 2;
sMatrix[1,0] = 3;
sMatrix[1,1] = 4;
to something like
sMatrix[,0] = BarsArray[0]
sMatrix[,1] = BarsArray[1]
Many thanks in advance!
Originally posted by mrlogik View PostA simple example of an integer matrix
Code://Define the matrix [FONT=monospace]int[,] sMatrix; //Initialize the matrix and define the size Initialize() { //this is a 2x2 matrix int[,] sMatrix = new int[2,2]; } //Now, lets use the matrix a little OnBarUpdate() { //matrix starts at index 0,0 sMatrix[0,0] = 1; sMatrix[0,1] = 2; sMatrix[1,0] = 3; sMatrix[1,1] = 4; //this matrix looks like this in memory /* 0 1 [/FONT][FONT=monospace]---------[/FONT] 0[FONT=monospace]| 1 | 2 | [/FONT][FONT=monospace]---------[/FONT] 1[FONT=monospace]| 3 | 4 | -------- */ } [/FONT]
Here's some more information
Hope this helps.
Comment
-
Stefy,
What type of data are you trying to save into the array? The example I gave will hold int type data; BarsArray[1] holds DataSeries type. Can you give a little more information as to what you're trying to do. It looks like you're trying to save bar (Open / High / Low / Close / Volume) data. If so, (can someone else comment) I believe you should have the ability to reference those directly from the BarsArray object.
Comment
-
Hi again mrlogik,
You're absolutely correct, BarsArray[1] holds DataSeries type. From your example, I changed already from int to double to consider prices.
I'm working on DIA (BarsArray[0]) and SPY (BarsArray[1]).
I want to calculate their covariance on the close prices, and then I want to run a multi regression on the close prices of those two securities.
So, I want to fill up a Matrix with:
sMatrix[,0] = BarsArray[0].Close
sMatrix[,1] = BarsArray[1].Close
If I can populate the matrix with BarsArray directly, that's also fine indeed. I would just like to know how to do it (an example would help). I tried to use the link from MSDN but didn't manage yet.
Thank you very much!
Originally posted by mrlogik View PostStefy,
What type of data are you trying to save into the array? The example I gave will hold int type data; BarsArray[1] holds DataSeries type. Can you give a little more information as to what you're trying to do. It looks like you're trying to save bar (Open / High / Low / Close / Volume) data. If so, (can someone else comment) I believe you should have the ability to reference those directly from the BarsArray object.
Comment
-
stefy, try something like this:
That is an oversimplified example but hopefully it will put you on the right track. Note that I assumed that all barseries have the same number of bars (ie, time based and using the same timeframe).Code:for (int i = 0; i < CurrentBar; i++) { sMatrix[0, i] = Closes[0][i]; sMatrix[1, i] = Closes[1][i]; }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
566 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
330 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
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment