Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

For analysis in CSV or Excel

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

    For analysis in CSV or Excel

    Is it possible to analyze historical transaction data in CSV or Excel obtained from a third party on the Ninja platform?

    #2
    Hello ラリー,

    Yes you can use any C# means to read external data like .csv files. There is a sample of using a stream reader in the following link:



    There is a post about using excel files in the following link, this is not something our support can help with but there is a large amount of information in the post. NT8 related information is near the end of the pages on that post: https://ninjatrader.com/support/foru...96-ninja-excel
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      Is the source code in the article you sent us the link to be replaced with this one (attached)?

      Attached Files

      Comment


        #4
        Hello ラリー,

        No those are two separate topics. The first link I provided shows how to use C# built in features to read from .csv files. The second link is an unsupported Microsoft excel api to interact with Microsoft excel documents. That post was for NT7 originally but there are NT8 details nearing the end of that post as well. NinjaScript is C# language and NinjaTrader can reference C# dlls as described in that post.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          I see that you did.

          I imported the SampleStreamReader_NT8.zip from the article in the link you sent me in the first place, but then I think I would open the text file in the stream reader, which one can I open it from?

          Comment


            #6
            Hello ラリー,

            The first sample I had provided shows how to read .csv files and parse the text inside the file. If you would like to learn more about reading .txt or other type of files I would suggest to search online for C# tutorials to do that. Reading files is not NinjaScript specific, that is part of C# and how the StreamReader works. For example searching for "C# streamreader read text" will bring up many examples including on from Microsoft: https://docs.microsoft.com/en-us/dot...xt-from-a-file

            The sample that I provided also goes into some detail about parsing the text data from the .csv file. The file extension does not really matter as long as the contents is a string or text, the streamreader can be used to read that text in C#.

            In your question you asked about both .csv and excel so I provided resources for both of those topics. You can choose which you wanted to use based on the type of file. Excel files are not text files so you would need to use that second link if you waned to read excel files specifically.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you for your reply.

              Please allow us to contact you again to attempt the above.

              Comment


                #8
                I will keep you informed of our progress.

                I first tried to open the CSV file in stormreader.
                I first tried to open it in stormreader with CSV and applied it to ninja script, but nothing is shown.
                Is this correct?
                Attached Files

                Comment


                  #9
                  Hello ラリー,

                  The sample does not display anything on the chart. You would need to review the code to see how the text is being read into the code. The purpose of that sample is to show how the C# feature streamreader works to read files. There is also logic in that to show how to parse the text data.

                  If you are having trouble understanding how streamreader works or how parsing text works you can find C# tutorials online to learn how to use those features. the streamreader is part of C# which is the language NinjaTrader uses for NinjaScript. There are a large number of tutorials and courses for C# in external sites. You can use a search engine like google to search for "C# streamreader examples" or "C# parse text from csv file" as some examples.

                  NinjaScript uses the NinjaScript Print statement in a lot of samples to output data to the output window which is what the streamreader sample does. Most samples you find wont do anything visual but instead are a way for you to look at what code is needed to do a task, you will need to read through the code to make sure you understand all the concepts it is using.



                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Thank you for your response.

                    I tried to run it and the output result shows that the symbols were loaded in visualstudio2022 as shown in the attached image, is this behavior correct?

                    NinjaScript uses the NinjaScript Print statement in a lot of samples to output data to the output window which is what the streamreader sample does. Most samples you find wont do anything visual but instead are a way for you to look at what code is needed to do a task, you will need to read through the code to make sure you understand all the concepts it is using.
                    Is it correct to say that the output is output on the Ninja script side?


                    Attached Files

                    Comment


                      #11
                      Hello ラリー,

                      You don't need to use visual studio to run that sample, you would just apply it to a chart and then observe the NinjaScript output window.

                      https://ninjatrader.com/support/help...nt8/output.htm

                      Unless you are extremely comfortable with using visual studio outside of NinjaTrader I would not suggest using that tool for debugging NinjaScript objects. We can't provide help on how to use visual studio directly however it can be used to attach to NinjaTrader and step through code. if you are familiar with debugging C# code in your own external C# projects it would be the same process.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Thank you for your reply.

                        It looks like the output is text or something, not from CSV, is this correct behavior?
                        Attached Files

                        Comment


                          #13
                          Hello ラリー,

                          That looks like its reading the .csv data and printing it to the output window. That script uses some logic to parse dates so if the data used does not match the output window you would need to make modifications to match the data you used. If you just wanted to print the .csv data you can remove the logic checking for dates and other parsing its doing and just print the read text.

                          .csv data is just a text file that's separated, csv means comma separated values so the output being text is correct because the input was also just text.

                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Thank you for your reply.

                            Is it possible to do the same with CSV data (not data retrieved within Ninja trader) that contains not only numbers but also strings (buy, sell, etc.), including logic and analysis?
                            Attached Files

                            Comment


                              #15
                              Hello ラリー,

                              Yes a csv file is just a text file, you can type anything you wanted in the file as long as its in the same format using commas or a specific symbol as a delimiter. If you review the code in the sample you can see that the file is being read line by line which is how each line is a new element. The data on each line is separated by commas and the line which is read is split using the comma as the delimiter.

                              As a side note you don't need to include quotes in the csv file, that is already a string. Quotes " " are only needed in C# code to denote a string.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Haiasi, 04-25-2024, 06:53 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post Massinisa  
                              Started by Creamers, Today, 05:32 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Creamers  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              12 responses
                              1,785 views
                              0 likes
                              Last Post Leafcutter  
                              Started by poplagelu, Today, 05:00 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post poplagelu  
                              Started by fx.practic, 10-15-2013, 12:53 AM
                              5 responses
                              5,407 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Working...
                              X