Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnStartup called multiple times during backtest?

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

    OnStartup called multiple times during backtest?

    Hi Ninjas,

    According NT7 help regarding OnStartUp():
    "This method is called only once immediately prior to the start of your script processing its logic in OnBarUpdate(), but after the Initialize() method."

    I tried to use this method to write description line (just first row: entry/exit, profit/loss long/short...etc) to own logfile.
    However, I found out the logfile contains multiple lines, i.e. seems like OnStartUp() is called and writes the line to logfile more then once when running backtest on basket of instrument.
    Can you specify conditions under which OnStartUp is re-called or how to avoid re-calling it?
    Using NT7.14

    Thanks in advance.

    BR.
    Q.

    #2
    Hello qoheleth,

    Thanks for your note.

    I have created a sample for you to test.

    On a regular backtest, this strategy is only writing once to the file per test.

    This strategy will write to (My) Documents\NinjaTrader 7\MyTestFile.txt.

    Please let me know if this is not behaving as expected.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      Hi,

      I tried code attached, same as yours but slightly modified. I'm trying to log trades in OnExecution method.
      I ran it on basket of intrument (ZC), log file indicates the same behaviour as before.
      Number of initial message equals to number of contract months in basket of instrument, so looks like OnStartUp() is called every time new contract month is backtested.
      Do you have any idea how to enter description line to log file only once?
      Thanks in advance.

      BR.
      Q.
      Attached Files

      Comment


        #4
        When you're running a backtest over a basket the script will be restarted each time for each instrument.

        The only way I can think to prevent OnStartup from printing to the text file each time would be to use some sort of text checking to see if it has already been written.

        You could use streamreader to do this however you would need to be sure you didn't both read and write to the file at the same time


        There may be other ways as well so I'll leave this open for others to provide their thoughts on.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Solution

          Hi Lance,

          sorry for later response, attached what I ended up with.
          To avoid writing first line every time OnStartUp() is called during the backtest, I used string comparison.
          I supposed OnStartUp() method is called only once and therefore there I wanted to delete old logfile right before starting of new backtest.
          Since OnStartUp() is called multiple times, I needed to introduce static variable (called "deleted") to delete old logfile.
          Static property ensures this variable is not re-initialized when new contract month of intrument basket is backtested (and OnStartUp() is re-called).
          However, this has the disadvantage: whenever I would like to run backtest again (with diff. strategy params), the file is not deleted (static variable "deleted" is already set to true), and hence new results of trades are appended to old ones.
          Of course other static variables has the same problem.
          Solution is to recompile the script. And this lead me to ideas for new major NT releases:
          1.) in NT7 it's not possible to complile and run NT backtest script from windows command line.
          I mean something like: "D:\NT7\bin\backtest.exe -complile_before_run true -strategy_script myBacktestScript.cs -instrument_basket ZC -strategy_params p1=3 ..... px=5 -mode backround etc..."
          I think this would be very helpful for automating and optimizing of strategies.
          2.) Interactive Brokers (I believe not only them) restrict quantum of historical data that can be downloaded in certain time. Reason is IB's servers oveload. For example if I violate downloading policy, I'm blocked for 5 minutes. I think another user-friendly idea is to introduce downloading of historical data and converting them to NT format from windows command line (similar to example at point 1.)). This will allow NT users to automate and schedule downloading of large amounts of hist. data (e.g. minute data)

          Can you please ask NT development team to consider this?
          Thanks in advance.
          BR.
          P.
          Attached Files

          Comment


            #6
            Thank you for the feedback. I will pass your suggestion off to development for the first item.

            For the second item this is an issue specific to IB

            Many Interactive Broker users choose to supplement their data with the Kinetick Data feed.

            Kinetick has been designed to be the optimal market data feed for the NinjaTrader 7 platform and is Free for End of Day data for stocks, futures and Forex.
            Streaming real-time quote service start as low as $50/month and you can even have your CME exchange fees waived with a qualified brokerage account. Please see the Kinetick website for more information: http://www.kinetick.com/
            You'll also enjoy all these benefits with any Basic Service subscription:

            * Fast, unfiltered data
            * Live data for 500 Market Metrics Indices are automatically included. Full list at: http://www.kinetick.com/market-metrics
            * Eliminated exchange fees for qualified accounts: http://www.kinetick.com/CME
            * Free Globex upgrades for qualified accounts
            * Free delayed and historical data for other exchanges not subscribed to
            * Free news from RTT News, PR Newswire, and Business Wire

            Let me know if I can further assist.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Spreads

              Hi Lance,

              thanks for promt response.
              What about Spread charts? Planned in NT8?
              Here competitor platforms has relatively one up to NT.

              BR.
              P.

              Comment


                #8
                Spread charts are possible with custom coding.

                Examples and more info on this can be found here: http://www.ninjatrader.com/support/f...ad.php?t=44701

                I will have the request to have it integrated into NinjaTrader without custom coding submitted to development.

                Let me know if I can be of further assistance
                LanceNinjaTrader Customer Service

                Comment


                  #9
                  Kinetick

                  Hi Lance,

                  according Kinetcik website, if I'd like to have access to historical minute data I need to purchase Kinetick, but also to purchase NT7.
                  Is it mandatory? Right now I'd like to develop strategy, not to go live.

                  Thanks.
                  BR.
                  Q.

                  Comment


                    #10
                    You are not required to purchase a live NinjaTrader to use a live Kinetick connection.

                    This can all be done on the simulation version.
                    LanceNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ScottWalsh, 04-16-2024, 04:29 PM
                    7 responses
                    34 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by cls71, Today, 04:45 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post cls71
                    by cls71
                     
                    Started by mjairg, 07-20-2023, 11:57 PM
                    3 responses
                    214 views
                    1 like
                    Last Post PaulMohn  
                    Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                    4 responses
                    547 views
                    0 likes
                    Last Post PaulMohn  
                    Started by GLFX005, Today, 03:23 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post GLFX005
                    by GLFX005
                     
                    Working...
                    X