Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Matrix with Ninja trader

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    I see what you mean.

    Thanks sefstrat!
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #17
      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 Post
      A simple example of an integer matrix

      Code:
      //Define the matrix
      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 
         ---------
        0| 1 | 2 |
         ---------
        1| 3 | 4 |
          --------
        */    
      }
      


      Here's some more information

      Hope this helps.

      Comment


        #18
        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.
        mrlogik
        NinjaTrader Ecosystem Vendor - Purelogik Trading

        Comment


          #19
          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 Post
          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


            #20
            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];
            }
            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).

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by BraisedInBlue, Today, 06:43 AM
            0 responses
            4 views
            0 likes
            Last Post BraisedInBlue  
            Started by AaronKoRn, Today, 06:28 AM
            0 responses
            3 views
            0 likes
            Last Post AaronKoRn  
            Started by pjsmith, Today, 01:00 AM
            1 response
            12 views
            0 likes
            Last Post NT-Roland  
            Started by alejandro888, Yesterday, 08:41 PM
            0 responses
            9 views
            0 likes
            Last Post alejandro888  
            Started by UltraNIX, Today, 02:14 AM
            0 responses
            9 views
            0 likes
            Last Post UltraNIX  
            Working...
            X