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

Writing to text file using Path.Combine

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

    Writing to text file using Path.Combine

    Hi,

    I am using the following line of code to write to text file however the file that is being created has a different file name to the code, please see below.

    Code:
    private string    path                = Path.Combine(@"C:\quotes\", DateTime.Now.ToString("ddMMyy.ESF"));
    The file that is created has the following name;
    210113.ES9

    How can I amend the code so the output file is 210113.ESF instead?

    Regards,
    suprsnipes

    #2
    suprsnipes, I would suggest to break it up like this -

    path = Time[0].Date.ToString("ddMMyy") + ".ESF";
    path1 = Path.Combine(@"C:\quotes\", path);
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi,

      Thanks for your response. I tried the suggested code I'm sure there is something I am missing but I am getting errors such as;

      Code:
      path  = Time[0].Date.ToString("ddMMyy") + ".ESF";
      path1 = Path.Combine(@"C:\quotes\", path);
      I also tried private string in front as well.

      ----
      A field initializer cannot reference the non-static field, method, or property 'NinjaTrader.Indicator.tcpcamToQuotes.path' An object reference is required for the non-static field, method, or property 'NinjaTrader.Indicator.IndicatorBase.Time.get' Class member declaration expected.
      ] expected.
      Class member declaration expected. Class member declaration expected. Class member declaration expected. Class member declaration expected.
      ----

      If someone could suggested how I could fix this I would be very grateful,

      Regards,
      suprsnipes

      Comment


        #4
        Originally posted by suprsnipes View Post
        Hi,

        Thanks for your response. I tried the suggested code I'm sure there is something I am missing but I am getting errors such as;

        Code:
        path  = Time[0].Date.ToString("ddMMyy") + ".ESF";
        path1 = Path.Combine(@"C:\quotes\", path);
        I also tried private string in front as well.

        ----
        A field initializer cannot reference the non-static field, method, or property 'NinjaTrader.Indicator.tcpcamToQuotes.path' An object reference is required for the non-static field, method, or property 'NinjaTrader.Indicator.IndicatorBase.Time.get' Class member declaration expected.
        ] expected.
        Class member declaration expected. Class member declaration expected. Class member declaration expected. Class member declaration expected.
        ----

        If someone could suggested how I could fix this I would be very grateful,

        Regards,
        suprsnipes
        From what event/method are you calling the code?

        Comment


          #5
          If anyone is interested this is how I fixed this problem...

          Code:
          #region Variables
          
          private string path1                 = @"C:\quotes\";
          private string path2                 = DateTime.Now.ToString("ddMMyy") + ".ESF";    
          
          protected override void OnBarUpdate()
          then using as follows File.AppendAllText(Path.Combine(path1, path2), code here);

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X