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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by junkone, Today, 11:37 AM
            2 responses
            14 views
            0 likes
            Last Post junkone
            by junkone
             
            Started by frankthearm, Yesterday, 09:08 AM
            12 responses
            44 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by quantismo, 04-17-2024, 05:13 PM
            5 responses
            35 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by proptrade13, Today, 11:06 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by love2code2trade, 04-17-2024, 01:45 PM
            4 responses
            35 views
            0 likes
            Last Post love2code2trade  
            Working...
            X