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 dustydbayer, Today, 01:59 AM
          0 responses
          1 view
          0 likes
          Last Post dustydbayer  
          Started by inanazsocial, Today, 01:15 AM
          0 responses
          3 views
          0 likes
          Last Post inanazsocial  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          22 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Started by guillembm, Yesterday, 11:25 AM
          2 responses
          10 views
          0 likes
          Last Post guillembm  
          Working...
          X