Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

File.AppendAllTxt

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

    File.AppendAllTxt

    Hello,

    I have a strategy that uses File.AppendAllTex. When I insert the strategy into a chart, everything works fine but when I insert the strategy in the “Strategies” tab of the Ninjatrader control panel, File.AppendAllTex does not write to the file. Why not?

    Thanks in advance and regards.

    #2
    Hello soyjesus,

    Thank you for your post.

    Where within your code are you using File.AppendAllText? Could you provide a code snippet to illustrate how you're using it that works on a chart but not in the Control Center?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hello Kate,

      I'm using File.AppendAllText from "OnPositionUpDate". Here's several lines of my code:

      if ((Position.MarketPosition == MarketPosition.Flat) && (SystemPerformance.RealTimeTrades.Count > 1))
      {
      if ((State == State.Historical))
      {
      return;
      }
      else if (Registrar_Operaciones == true)
      {
      File.AppendAllText(FicheroOperaciones, Account.Name + '#');
      }
      }

      Comment


        #4
        Hello soyjesus,

        Thank you for your reply.

        From what you've got there that all looks like it should work - you may want to try putting in some prints to print what you're trying to append to the file to see if those print with the correct data.

        That being said, my colleague suggested that your setting for IncludeTradeHistoryInBacktest may be a factor when running it from the Control Center. If listed in your strategy, what is the current setting for this in State.SetDefaults? If it is not present or false, try setting this to true in State.SetDefaults - I know that for this particular one, it defaults to true on the 64 bit version of the platform unless the script is run from the Control Center directly. Since we're dealing with what looks to be completed order information, this could impact the items you're wanting the file to write.

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Hello Kate,

          I have found the bug. I call to SystemPerformance.RealTimeTrades.Count and this function doesn't work when I create the Strategy from the Control Center. Why not?

          Thanks and regards.

          Jesus.

          Comment


            #6
            Hello soyjesus,

            Thank you for your reply.

            Those properties in SystemPerformance require that IncludeTradeHistoryInBacktest be set to true. This would need to be explicitly set in State.SetDefaults for it to be true when running a strategy from the Strategies tab of the Control Center. Note that you will need to create a new instance of the strategy after adjusting this instead of using one already listed in the Control Center for the changes to be picked up.

            Thanks in advance; I look forward to assisting you further.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            62 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            134 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X