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

Dev Question

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

    Dev Question

    Greetings, have two questions.

    Am developing a strategy which relies on getting 4 parameters specific to each instrument from an external DB (MS Access). So within the external DB I have ~200 stocks with their associated 4 parameters. As a traverse through the ~200 stocks during backtesting, I need to determine which instrument I’m on to make the correct call to fetch the corresponding record in Access. Is the Initialize() method called once per instrument tested? So if I were backtesting 200 instruments, it would be called once for each new instrument being tested? And second, what property can be accessed within Initialize() to tell me what instrument I’m on? Need this as a parameter to pull the right values from my Access DB.

    Many thanks for the help!

    #2
    Originally posted by dosjots View Post
    Greetings, have two questions.

    Am developing a strategy which relies on getting 4 parameters specific to each instrument from an external DB (MS Access). So within the external DB I have ~200 stocks with their associated 4 parameters. As a traverse through the ~200 stocks during backtesting, I need to determine which instrument I’m on to make the correct call to fetch the corresponding record in Access. Is the Initialize() method called once per instrument tested? So if I were backtesting 200 instruments, it would be called once for each new instrument being tested? And second, what property can be accessed within Initialize() to tell me what instrument I’m on? Need this as a parameter to pull the right values from my Access DB.

    Many thanks for the help!
    dosjots,

    I do not recommend doing that in Initialize() since it will be called multiple times.
    I would recommend moving to OnBarUpdate() and using somekind of toggle to make sure you call it once.
    Something like if(CurrentBar == 0) or using custom variable.

    Comment


      #3
      Hey Roonius, thanks for the response. I had thought that Initialize() was only called once per instrument. If multiple times, then yes I'll stick with OnBarUpdate(). Is there a property that you're aware of that I can look up the instrument name?

      Thanks again-

      Comment


        #4
        Originally posted by dosjots View Post
        Hey Roonius, thanks for the response. I had thought that Initialize() was only called once per instrument. If multiple times, then yes I'll stick with OnBarUpdate(). Is there a property that you're aware of that I can look up the instrument name?

        Thanks again-
        Initialize() is called only once per "primary bar"...

        But Initialize() can be called at some what arbitrary times in addition to when you actually run the strategy... it's called as soon as you open up the "New Strategy" window, for example. I think it does this just to pull out the default property values needed to populate the various fields for your "new strategy".

        I've always found that to be a little annoying... but that's life.

        Comment


          #5
          Originally posted by dosjots View Post
          Hey Roonius, thanks for the response. I had thought that Initialize() was only called once per instrument. If multiple times, then yes I'll stick with OnBarUpdate(). Is there a property that you're aware of that I can look up the instrument name?

          Thanks again-
          Bars.Instrument.FullName

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wuannetraam, Today, 02:40 AM
          0 responses
          7 views
          0 likes
          Last Post wuannetraam  
          Started by cyberpete76, 03-27-2023, 12:29 AM
          7 responses
          268 views
          1 like
          Last Post slightly  
          Started by renewsaltwater, Today, 01:15 AM
          0 responses
          2 views
          0 likes
          Last Post renewsaltwater  
          Started by slightly, Today, 12:49 AM
          0 responses
          4 views
          0 likes
          Last Post slightly  
          Started by sdauteuil, 09-23-2021, 10:16 AM
          4 responses
          1,211 views
          0 likes
          Last Post jacobpescaia44  
          Working...
          X