Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how about I/0 in ninja?

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

    how about I/0 in ninja?

    hello,first,thanks a lot for this useful and unique software.I am studying it.
    can supporter tell me the I/0 in this software.
    for example, I want do some stactistic,and must output data into a txt file.
    pls tell me the syntax.thanks a lot.

    #2
    Ironically today I fixed a bug in a NT7 Strategy I wrote a few months ago to do just that. I use it with R. You might find it useful or get some ideas from it.

    It exports DateTime, O,H,L,C data to txt or csv files, and in the code are notes on how to get it to exort indicator values as well.

    FWIW the bug was an exception was thrown if a space was used in the path variable ("My Documents", for example).

    Good luck!
    Attached Files

    Comment


      #3
      yes ,I need this ,thanks a lot.I will try it.

      Comment


        #4
        first ,thanks for your post ,and I have had a idea about how to export DTOHLCV data to a txt file or csv file.
        I have tried to open the attachment you post.but cannot.
        I would like to get some information like this:
        print("d:\testdata.txt",sma(15)[20]),can ninjatrader do this and the how about the syntax?

        Comment


          #5
          It is a NT 7 Strategy. In NT 7, go to File>Utilities>Import Ninjascript, and point to that zip file.

          Then go to the "Strategies" tab, right click and select New Strategy, select ExportData and use the parameters you want. Then tick the Enable box if you are connected to your historical data source. As it is a Strategy you can also apply it to an Instrument List.

          If you have an output window it will tell you were the data is being written.

          Disable the strategy once all the data has been loaded to write and close the file.

          If you are on NT6.5 it won't work as-is but will require some code changes.

          It uses System.IO and StreamWriter.

          Comment


            #6
            thanks a lot.

            Comment


              #7
              silverness, the reference sample for writing data to a file can be found here.
              AustinNinjaTrader Customer Service

              Comment


                #8
                MXASJ,
                Thanks for the script. Just what I had been looking for. But this file is exactly as the last one you uploaded here. Would you be able to share the script you alluded to in above so indicator values can be retrieved too?

                Cheers.

                Comment


                  #9
                  How to do it is in the notes in the code. Here is OnBarUpdate:

                  PHP Code:
                  protected override void OnBarUpdate()
                    {
                   
                     
                  // This is the output of all lines. The output format is: DateTime Open High Low Close Volume
                     // If you wanted to output indicator data you could add that to string "data" as well, for example:
                     //string data = (Time[0] + dataSeparator + Open[0] + dataSeparator + High[0] + dataSeparator + Low[0] + dataSeparator + Close[0] + dataSeparator + EMA(14)[0]);
                   
                     
                  string data = (Time[0] + dataSeparator Open[0] + dataSeparator High[0] + dataSeparator Low[0] + dataSeparator Close[0] + dataSeparator Volume[0]);
                   
                     if (
                  splitDateTime == true)
                      {
                  //Replace the space in DateTime with the DataSeparator
                      
                  data data.Replace(@" ",dataSeparator);
                      }
                   
                     
                  sw.WriteLine(data);
                   
                    } 
                  In the commented-out example it records EMA(14) instead of volume. If you wanted just DateTime, Close, and EMA you would write:

                  PHP Code:
                  string data = (Time[0] + dataSeparator Close[0] + dataSeparator EMA(14)[0]); 

                  Comment


                    #10
                    Got it to work, thanks MX.

                    Comment


                      #11
                      Export Data

                      Hi Max, great job on this. Being able to exporting chart data to excel has saved so much time. I had a couple of questions on it though.

                      1. I was having problems saving my own file. When I selected usedefaultfilename as "false" and put my own file name in it said "invalid path, although I hadn't changed the path at all. Was wondering if I had done something wrong.

                      2. I'd like to analyze delta volume as part of an excel analysis I'm doing. So I put in this line (See the reference to Gom's deltamomentum indicator at the end. When I compile it there is no problem, but when I view the output the field is showing all zeros. Any help on this would be appreciated. Thanks. DJ

                      string data = (Time[0] + dataSeparator + Open[0] + dataSeparator + High[0] + dataSeparator + Low[0] + dataSeparator + Close[0] + dataSeparator + HMA(10)[0] + dataSeparator + GomDeltaMomentum().DeltaMomo[0]);

                      Comment


                        #12
                        djkiwi,

                        First step I would take is to eliminate any potential writing to file issues and first just see via a Print() call what exactly those values are.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks djkiwi,

                          I just tried setting useDefaultFileName to false, and tried both "test" and "test.txt" as filenames and it works OK. Here is my Output Window:

                          Code:
                          **NT** Enabling NinjaScript strategy 'ExportData/dd9bb80e79014c789233fbeb304d8564' ...
                          2010-12-15 06:14:35 Running Export Data
                          Writing to file: D:\Data\test.txt
                          Disable to close the file and allow access by other programs.
                          **NT** Disabling NinjaScript strategy 'ExportData/dd9bb80e79014c789233fbeb304d8564'
                          2010-12-15 06:14:40 Terminating ExportData on $USDJPY 1 Minute Data
                          File written to: D:\Data\test.txt
                          **NT** Enabling NinjaScript strategy 'ExportData/dd9bb80e79014c789233fbeb304d8564'...
                          2010-12-15 06:15:08 Running Export Data
                          Writing to file: D:\Data\test.txt.txt
                          Disable to close the file and allow access by other programs.
                          **NT** Disabling NinjaScript strategy 'ExportData/dd9bb80e79014c789233fbeb304d8564'
                          2010-12-15 06:15:11 Terminating ExportData on $USDJPY 1 Minute Data
                          File written to: D:\Data\test.txt.txt
                          The "Invalid Path" error is part of a Try/Catch block in OnStartUp(). I hate to sound like a support guy but can you give me some steps so I can try to reproduce it on my end? .

                          And Josh is right on the Print() statement as a good way to troubleshoot. I don't have the Gom stuff on my computer so I can't test here.

                          Raw cs file of the latest code of the ExportData strat is attached. It adds an enum for DateTime output format. Not 100% tested yet.
                          Last edited by MXASJ; 12-14-2010, 05:44 PM. Reason: EDIT: Removed raw cs file and updated in later post.

                          Comment


                            #14
                            Output window

                            Hi Guys, thanks for the fast responses. Well I did the output window part and this is what it says, looks like a security attributes issue. Interesting that it does not cause a problem writing the default file but when I try to write to a different file it causes a problem.

                            Max, please note that the GOMI thing does in fact work ok. Some of my data was missing so was not seeing it.


                            Thanks DJ.

                            Exception Details: System.IO.IOException: A required privilege is not held by the client.

                            at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
                            at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
                            at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
                            at System.IO.StreamWriter.CreateFile(String path, Boolean append)
                            at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
                            at System.IO.StreamWriter..ctor(String path, Boolean append)
                            at System.IO.File.AppendText(String path)
                            at NinjaTrader.Strategy.ExportData.OnStartUp()
                            **NT** Error on calling 'OnStartUp' method for strategy 'ExportData/d0ecbec61f4e447388cabced73c86122': Object reference not set to an instance of an object.

                            Comment


                              #15
                              That error message indicates you don't have permission to access the file you are trying to write to. That was received on your StreamWriter lines and not to do with the Print() method.

                              Suggest you use some try-catch blocks to isolate out exactly which line in your code threw this error if it is not immediately evident through your code where you ran into it. http://www.ninjatrader.com/support/f...ead.php?t=9825
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by egordleo, Today, 05:50 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post egordleo  
                              Started by kevinenergy, 02-17-2023, 12:42 PM
                              118 responses
                              2,778 views
                              1 like
                              Last Post kevinenergy  
                              Started by briansaul, Today, 05:31 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post briansaul  
                              Started by fwendolynlpxz, Today, 05:19 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post fwendolynlpxz  
                              Started by traderqz, Yesterday, 12:06 AM
                              11 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X