Thanks sefstrat!
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
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:
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 Aviram Y, Today, 05:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by Aviram Y
Today, 05:29 AM
|
||
Started by quantismo, 04-17-2024, 05:13 PM
|
3 responses
25 views
0 likes
|
Last Post Today, 05:23 AM | ||
Started by ScottWalsh, 04-16-2024, 04:29 PM
|
7 responses
34 views
0 likes
|
Last Post Today, 05:15 AM | ||
Started by cls71, Today, 04:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by cls71
Today, 04:45 AM
|
||
Started by mjairg, 07-20-2023, 11:57 PM
|
3 responses
216 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
Comment