Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy start hook

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

    Strategy start hook

    Hi guys

    I need a hook which will allow me to run some code when a custom strategy is started. At the moment I've overridden the Initialize() method and placed my setup code in there. However, I've got all kinds of problems (such as TickSize not being accessible) because that method is called any time an instance strategy is created. Obviously this can happen before any instrument has been selected.

    There must be some way for me to determine when the strategy has started and pick up info such as the TickSize.

    Thanks.

    #2
    Please try this:
    - define a boolean flag variable, set to true
    - first time OnBarUpdate is called check if flag is true and then
    * run your Init() stuff
    * set flag variable to false

    Comment


      #3
      Already tried that. The problem is the L2 order book gets built before OnBarUpdate() is called for the first time. What I need is a hook which allows me to setup my strategy before any market data events get fired.

      Comment


        #4
        ScoobyStoo,

        Maybe I am missing something but I am not seeing why there is such a requirement of doing this before receiving data events. What is it that you need to build beforehand?
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          ScoobyStoo,

          Maybe I am missing something but I am not seeing why there is such a requirement of doing this before receiving data events. What is it that you need to build beforehand?
          It's OK, don't worry about it. I need to construct a ton of objects required by the strategy prior to it beginning to process market data. I've fixed it by including a call at the beginning on each overridden market data method to determine if the strategy has been initialised and if not to initialise it. That way I know that whichever market data event is raised first, the strategy will get correctly initialised. It's a really ugly solution though...

          Would be really handy for NT7 to expose proper hooks to all the strategy lifecycle events (start, pause, stop etc). Obviously, I don't know how difficult that would be to do though...

          Thanks for the help

          Comment


            #6
            Great you got it working, thanks for the suggestions ScoobyStoo.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            60 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            147 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            162 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            97 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            284 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X