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

Creating a one dimensional array

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

    Creating a one dimensional array

    Hey guys.

    Is there a way to create and permanently store an array, that I can call up and use within various indicators/scripts that I need?

    My idea, if it's possible is to create a simple txt file formatted accordingly of course, that will use a series of values (static, I don't need to change it, just access the values). Then I would like to 'call' the array, already populated, and then just access it within my coding/indicator scripting.

    I would prefer this method if possible since it would greatly simplify the programming.

    The values in the array are not taken from any indicators or price series or anything else like that so I don't really know how to populate the array without programming the entire thing at run-time one cell at a time, which seems like a poor way to do things. In fact at this point I don't even know how I would do that anyway.

    Before I put pen to paper I want to see what my options are with respect to array building and populating within the NT, C# environment.

    #2
    I think there are a ton of ways you can do this depending on exactly what you need to do, but if you just want to write to a txt file, try StreamWriter/Reader.

    Comment


      #3
      Originally posted by Radical View Post
      I think there are a ton of ways you can do this depending on exactly what you need to do, but if you just want to write to a txt file, try StreamWriter/Reader.
      lol i don't want to write to a text file. I want to READ a text file, LOAD it to an ARRAY, to use in my script.

      What I don't want to do, if possible, is to code and populate an array (if I can even do that anyway) at start-up or run time. I don't want to hard-code the array into a script either.

      I'd much prefer to hard-code the script and have it call the appropriate (pre-made) array, from a file, since the array value will be different depending on the security involved.

      Hopefully that is clearer since I know these things can get wordy real quick with miscommunication being rampant by its very nature with this stuff.

      Comment


        #4
        Ok, can't you just read whatever data you need from the txt file into an array at runtime?

        Comment


          #5
          Originally posted by Radical View Post
          Ok, can't you just read whatever data you need from the txt file into an array at runtime?
          Hopefully YES!

          Any idea how?

          That sounds exactly what I want to do.

          At run-time is perfectly fine, but what I guess I really want it most for is so I don't have to hard-code the array into the script. Plus I've got the problem of not knowing if it' possible to read and run-time nor do I know how it's done.
          Last edited by Steve R; 08-15-2012, 09:42 AM.

          Comment


            #6
            Like I said, I think there are probably many ways to do this, but check out StreamReader.

            Comment


              #7
              Hello Steve R,

              If you want some static variable it would have to be either hard coded inside NinjaScript or like you mentioned to be read from a text file that can be read. With the first option you could create a UserDefinedMethod with your hard coded values in.

              http://www.ninjatrader.com/support/h...ed_methods.htm

              Otherwise you could use the read from a text file and create your array based upon the delimiter you specify. You can a reference of how to read from an text file from the following forum post.
              http://www.ninjatrader.com/support/f...ead.php?t=3476

              With that said you could also look into creating your own Array call with C#, but this would be unsupported.
              http://msdn.microsoft.com/en-us/libr...tem.array.aspx

              Let us know if we can be of further assistance.
              JCNinjaTrader Customer Service

              Comment


                #8
                OK guys, that looks like what I am after. Of course I was hoping NT would make it a little easier, lol.

                It looks like JC's # 2 option is what I'll be going after. I have no clue what StreamReader is but I guess I am going to get acquainted.

                Let me hit the drawing board for a bit. I'll likely need to get back to you with more questions sooner or later.

                Thx guys.

                Comment


                  #9
                  Originally posted by Steve R View Post
                  OK guys, that looks like what I am after. Of course I was hoping NT would make it a little easier, lol.

                  It looks like JC's # 2 option is what I'll be going after. I have no clue what StreamReader is but I guess I am going to get acquainted.

                  Let me hit the drawing board for a bit. I'll likely need to get back to you with more questions sooner or later.

                  Thx guys.
                  wait wait, just one second here. I'm looking at the UserdefinedMethod here since the StreamReader looks way too complicated for what I need to do.

                  Let me give you a snip and then you can tell me what I should do. I apologize in advance for possibly using incorrect terminology..

                  So,I want an array. Let's call it 5 cells? (Is 'cell' the right term?)

                  Cell 0 Value is 1.23
                  Cell 1 Value is 1.45
                  Cell 2 Value is 2.10
                  Cell 3 Value is 4.35

                  etc..

                  Note that I'll need about 150 cells in reality and ALSO note that the values are not linear nor are they overly easy to calculate (although yes, I could code it, but what a waste) - which is why I just want to manually place them once in a file, then to a static array and be done with it. Then I'll call the array cell # and get the value as I need it.

                  What's the easiest way?
                  Last edited by Steve R; 08-15-2012, 10:19 AM.

                  Comment


                    #10
                    I don't think you're going to get much simpler than StreamReader....you can accomplish what you want in like 10 lines of code.

                    Comment


                      #11
                      Originally posted by Radical View Post
                      I don't think you're going to get much simpler than StreamReader....you can accomplish what you want in like 10 lines of code.
                      OK you start with the first 10 lines and I swear I'll take it from there...

                      I've got a txt file full of the values, separated by comma's semi-colons,..whatever you want..

                      Call the text file whatever you want too :-)

                      I'm sitting in my main script and I want to call up the value in the first cell of the array from the txt file,...and.....

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by lightsun47, Today, 03:51 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post lightsun47  
                      Started by 00nevest, Today, 02:27 PM
                      1 response
                      8 views
                      0 likes
                      Last Post 00nevest  
                      Started by futtrader, 04-21-2024, 01:50 AM
                      4 responses
                      45 views
                      0 likes
                      Last Post futtrader  
                      Started by Option Whisperer, Today, 09:55 AM
                      1 response
                      14 views
                      0 likes
                      Last Post bltdavid  
                      Started by port119, Today, 02:43 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post port119
                      by port119
                       
                      Working...
                      X