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

Which method is called only once at the end of the script?

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

    Which method is called only once at the end of the script?

    While doing a back test on a particular instrument, my strategy keeps a count of a certain number of events (in this case, gaps). Once the strategy finishes running on this instrument, I would like to print this data to a file? Which method should I put that code in?


    I've tried putting it in OnStateChange (State==State.Terminated) but it appears I lose the value of my variables. Otherwise I'm not sure where it should go.


    So my question should be, which method gets called only once as soon as a back test completes?


    Thanks!

    #2
    Hello Jeffsg605,

    Thank you for your note.

    You could use streamwriter to save your trade information to a file.

    See the following section of our helpguide.


    If you use Streamwriter in State.Terminated, does it save the information to the file as desired?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi Alan,


      Thank you for responding but I think you missed my question. I don't need help writing to a file. As I stated in my initial question:



      "I've tried putting it in OnStateChange (State==State.Terminated) but it appears I lose the value of my variables."


      The value I want to keep track of has already been reset to 0 in State.Terminated. So to repeat my question, which method gets called only once as soon as a backtest completes?


      Thanks.

      Comment


        #4
        Hello Jeffsg605,

        I’ve attached a sample strategy which when you run in the strategy analyzer, upon completion, will print to the output window the value of a variable which has 1 added to it on each OnBarUpdate. So for example 300.

        Instead of printing, you could have this value written to a file.

        Please let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thanks, I'll give this a try tonight. For the time being, I got it to work by just checking to see if the date of the backtest is today's date (or the last tradeable day). If it is, then I write my file, otherwise, I continue. This is a little cleaner though, thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by puapwr, Today, 06:09 PM
          0 responses
          1 view
          0 likes
          Last Post puapwr
          by puapwr
           
          Started by franciscog21, Today, 05:27 PM
          0 responses
          4 views
          0 likes
          Last Post franciscog21  
          Started by hdge4u, 04-29-2024, 12:23 PM
          5 responses
          28 views
          0 likes
          Last Post MisterTee  
          Started by llanqui, 01-25-2024, 06:15 PM
          9 responses
          64 views
          0 likes
          Last Post MisterTee  
          Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
          16 responses
          66 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X