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

StreamWriter

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

    StreamWriter

    Another question on the StreamWriter. I have your StreamWriter Sample. If I want to use it inside a strategy, can I just call it as an indicator?

    Since the overload is IDataSeries, should I just put the DataSeries I want to print out to the file?

    #2
    Not sure what you mean. The sample is just a sample. Not sure if you would actually want to call the sample. You can use StreamWriter just the same in a strategy as you can in an indicator. Might be easier that way.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I meant, in your sample you print out Open, High, Low, Close.
      If I want to StreamWrite the Cumulative PNL of my strategy, can I just change your sample accordingly (changing the fields I want to print out) and then just insert StreamWriter into my strategy, as if it were an indicator?
      The syntax would be StreamWriter()?

      Comment


        #4
        That should work. The syntax would be incorrect as that is not the indicator name though. The term "StreamWriter" is also already used by C# so you likely can't name your indicator that.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I'm using StreamWriter now to print out to a file the PnL of a Strategy. Since I cannot reference the PnL from an Indicator, I'm adding the StreamWriter to the strategy itself.
          I followed your sample and added System.IO and in Variables System.IO.StreamWriter sw, then after the strategy code, the try catch block.

          It compiles but in the Log I get "Error on calling OnBarUpdate method: object reference not set to an instance of an object".

          What can be wrong? The strategy also doesn't run (all zeroes).

          Comment


            #6
            You will need to use try-catch blocks throughout your code to try and find where the error is being generated from. Please also see this tip if you are using IOrders. http://www.ninjatrader-support2.com/...ead.php?t=4226
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            1 view
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            238 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            383 views
            1 like
            Last Post Gavini
            by Gavini
             
            Started by oviejo, Today, 12:28 AM
            0 responses
            1 view
            0 likes
            Last Post oviejo
            by oviejo
             
            Started by pechtri, 06-22-2023, 02:31 AM
            10 responses
            125 views
            0 likes
            Last Post Leeroy_Jenkins  
            Working...
            X