Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 streamwriter replace - add

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

    NT8 streamwriter replace - add

    Hello,

    I´m working from the sample streamwriter and I could add it to my indicator. But it always replaces current values in the file. What do I have to add so that new values are added in the next line of the file? Can you please help me with a snippet.

    Thank you!
    Tony

    #2
    Hello tonynt,

    The StreamWriter is a standard C# object which has quite a few properties and methods, this is documented at MSDN:

    https://docs.microsoft.com/en-us/dotnet/api/system.io.streamwriter?view=netframework-4.5

    This can be combined with the File object and its AppendText method:
    Creates a StreamWriter that appends UTF-8 encoded text to an existing file, or to a new file if the specified file does not exist.


    The second link contains a sample of appending text to a file.


    I look forward to being of further assistance.

    Comment


      #3
      Hello,

      thank you for providing the link. When I modify my code (that is working) then I get an error-message when compiling

      "No overload for AppendText, takes 2 arguments" (translation by me!)

      (StreamWriter outputFile = File.AppendText(docPathC + @"" + dnFile,false))
      outputFile.WriteLine(string.Format("{0},{1},{2},{3 },{4},{5},{6},{7}",dn1xA,dn1xB,dn1xC,dn1xD,0,0,0,0 ));}

      Do you see whats wrong here please?

      Thank you!
      Tony

      Comment


        #4
        Hello tonynt,

        I see you have used two parameters for AppendText but it only takes one, this would be the comma false or:

        Code:
        File.AppendText(docPathC + @"" + dnFile[B],false[/B])

        It should just be the file path

        Code:
        File.AppendText(docPathC + @"" + dnFile )

        I look forward to being of further assistance.

        Comment


          #5
          Thank you

          Comment


            #6
            Hello Jesse,

            all is working fine with this help. But I have - always - problems with time, date.... What do I have to add please to my line posted here above to have dayofweek, date and time instead the "0" there.

            Thank you!
            Tony

            Comment


              #7
              Hello tonynt,

              I am not certain which syntax you are referring to here, did you mean to include some additional syntax? If you are referring to formatting a DateTime, you can see the following public link for some examples for formatting time: http://www.csharp-examples.net/string-format-datetime/

              I look forward to being of further assistance.

              Comment


                #8
                Hello Jesse,

                thank you for your reply. This time and date syntax makes me crazy. I mean to have here
                outputFile.WriteLine(string.Format("{0},{1},{2},{3 },{4},{5},{6},{7}",dn1xA,dn1xB,dn1xC,dn1xD,Date, DayOfWeek, Time));}

                Thank you!
                Tony

                Comment


                  #9
                  Hello tonynt,

                  If you are trying to print the Time, you would need to specify what BarsAgo you wanted. Time is the series, you still need to add a BarsAgo here:

                  Code:
                  Time[0]
                  Date and DayOfWeek seem to be some variables you have made. If those are 0 you would need to look at your logic to see why that is the case. DayOfWeek specifically is a NinjaScript enum as well, if you have made a variable named DayOfWeek I would suggest using a different name, if you are trying to print specifically DayOfWeek or Date from the Time, you need to not use the enum because that is not a value. You can access the Date or DayOfWeek from the time object:

                  Code:
                  Time[0].Date
                  Time[0].DayOfWeek
                  The Time object is a Series of DateTimes, so you can access any DateTime property from a specific time like shown above.



                  Please let me know if I may be of additional assistance.

                  Comment


                    #10
                    Why appears there " Unlike" when I click on "like" ???

                    Comment


                      #11
                      Hello tonynt,

                      That just is to give confirmation you liked the post, you can also unlike a post if you feel later you stopped liking it.

                      Please let me know if I may be of further assistance.

                      Comment


                        #12
                        Hello,

                        now its clear once the post sent as I recognize now. But when you click it then there appears "Unlike" "1" side by side! This means? "Unlike 1" after clicking.

                        Best regards
                        Tony

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        574 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        332 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        553 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        551 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X