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!
See more
See less

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
      [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


        #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 bill2023, Yesterday, 08:51 AM
            8 responses
            43 views
            0 likes
            Last Post bill2023  
            Started by yertle, Today, 08:38 AM
            6 responses
            25 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            24 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            46 views
            0 likes
            Last Post jeronymite  
            Working...
            X