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

binary file: how to Read and Write

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

    binary file: how to Read and Write

    Josh or any advanced c# programmer please help!

    Please. show example how to read from binary file (how open, read and close binary file correct).

    Exactly how to read in array.

    -----------------------------------------------------------------------
    I didn't find complete examples on forum, and examples from MSDN didn't work
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    fx.practic, please check into the refererance samples we have published here - http://www.ninjatrader-support2.com/...splay.php?f=30

    There're entries for using System.IO File and StreamReader / Writer to reading / writing from files.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Here http://www.ninjatrader-support2.com/...splay.php?f=30 there are 3 three threads about files I/O:

      1. Indicator: Using System.IO File properties to write to and read from a text file (http://www.ninjatrader-support2.com/...ead.php?t=3477)

      2. Indicator: Using StreamReader to read from a text file (http://www.ninjatrader-support2.com/...ead.php?t=3476

      3. Indicator: Using StreamWriter to write to a text file (http://www.ninjatrader-support2.com/...ead.php?t=3475

      This samples illustrate how to use text files only.

      To everybody who will interesting in binary files I propose my empirisch experience.
      If advanced programmers can correct my example - you are welcome.


      using System.IO;
      ...........................

      string FILE_NAME = "C:\\Users\\Andrei\\Documents\\NinjaTrader 6.5\\files\\DigitFilter\\DigitFilter_0.bin";

      if(System.IO.File.Exists(FILE_NAME))
      {
      Log("Strategy DF_v01__Original: OK, file" + FILE_NAME +" is open", LogLevel.Information);
      FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);
      BinaryReader r = new BinaryReader(fs);
      try
      {
      int i = 0;
      while (true) {a_B_DiFi[0, i] = Math.Round(r.ReadDouble(), 8); i++; }
      }
      catch (Exception e) { r.Close(); fs.Dispose(); fs = null;}
      }
      else Log("Strategy DF_v01__Original: file "+FILE_NAME+" don't exist", LogLevel.Error);
      Last edited by fx.practic; 12-26-2009, 03:50 PM.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        Hallo, I tried to read and write from a file using the example in (http://www.ninjatrader-support2.com/...ead.php?t=3477)

        but if I copy and paste that code in my strategy, not using it as an indicator, I cannot read/write a file.
        Could anybody help me on this?
        Thanks in advance

        Comment


          #5
          marticora, welcome to our forums - any errors in the log tab if you run your modified stratregy then? Since the link you posted was broken, which sample did you use here?
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hallo Bertrand,
            I found the following indicator that works fine to read/write:


            I am very new to C# programming, so this is very likely a beginner mistake... but I am learning.
            I am trying to get the same above to run within a strategy file I am developping, but this does not work: in fact the file is not created and nothig happens.
            Attached you find what I did.
            Thank you
            Attached Files

            Comment


              #7
              It might not find your path, please try exact as per our sample -

              Code:
               
              private string path = [B]Cbi.Core.UserDataDir.ToString()[/B] + "SampleFileReadWrite-MyTestFile.txt";
              BertrandNinjaTrader Customer Service

              Comment


                #8
                It works!
                Thank you very much!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rdtdale, Today, 01:02 PM
                0 responses
                3 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by alifarahani, Today, 09:40 AM
                3 responses
                15 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by RookieTrader, Today, 09:37 AM
                4 responses
                18 views
                0 likes
                Last Post RookieTrader  
                Started by PaulMohn, Today, 12:36 PM
                0 responses
                9 views
                0 likes
                Last Post PaulMohn  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                41 views
                0 likes
                Last Post love2code2trade  
                Working...
                X