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

StreamWriter

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

    StreamWriter

    I have slightly modified example "SampleStreamWriter". First option works, but my code doesn't.
    I am trying to write data to my file at user defined location. It doest write at the same time no error message. How to write to a file at user defined location?
    Any help please?
    Regards,

    Code:
    protectedoverridevoid Initialize()
    {
    // path = Cbi.Core.UserDataDir.ToString() + Instrument.FullName + ".txt";
    path = "D:\\ForexData\\Ninja" + Instrument.FullName + ".txt";
    CalculateOnBarClose =
    true;
    }

    #2
    Hello,

    This works for me:
    privatestring path2 = "C:\\AFolderName\\MyTestFile.txt";

    Try starting over with the SampleStreamWriter file and just changing the one line above and this line (of course use a patht that will work on your computer):
    sw = File.AppendText(path2);

    Can you get that to work?
    DenNinjaTrader Customer Service

    Comment


      #3
      Thankyou Ben for your reply.
      I was missing two "\\" at the end of my path string. Its working now.
      Thanks a lot.

      Cheers,

      Comment


        #4
        How do I encapsulate an output sw.WriteLine(" This is Close Price "25" ");

        it is reading it to behaving 2 quotation marks at "25"

        there fore an error occurs during compile of the indicator.

        Comment


          #5
          For the streamwriter, it seems to be writing the the next line below,

          Is it possible to write on the line above?

          Is it possible to overwrite the existing file with the new entry? By deleting the previous line?

          Comment


            #6
            Oil_Trader, yes these are possible: to write something with quotes, please try putting an @ symbol in front of the string. As for how to overwrite the existing file, you'll have to review the MSDN documents on StreamWriter because I'm not intimately familiar with the process.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Can you give a specific example?

              This is what I am writing and yet is is saying ------> ) expected

              this is my code

              sw.WriteLine(@" SP500 ="1225.0" + NQ ");

              as you can see, there are quotation marks within the parameter

              Comment


                #8
                Hello OilTrader,

                You may have to use escape characters for the quotation marks. See the reference sample below for help with this:
                Indicator: Manipulating string objects
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by GLFX005, Today, 03:23 AM
                0 responses
                1 view
                0 likes
                Last Post GLFX005
                by GLFX005
                 
                Started by XXtrader, Yesterday, 11:30 PM
                2 responses
                11 views
                0 likes
                Last Post XXtrader  
                Started by Waxavi, Today, 02:10 AM
                0 responses
                6 views
                0 likes
                Last Post Waxavi
                by Waxavi
                 
                Started by TradeForge, Today, 02:09 AM
                0 responses
                11 views
                0 likes
                Last Post TradeForge  
                Started by Waxavi, Today, 02:00 AM
                0 responses
                2 views
                0 likes
                Last Post Waxavi
                by Waxavi
                 
                Working...
                X