• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Initialize invocation context and strategy status

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

    Initialize invocation context and strategy status

    Is there a way (almost certainly unsupported) to know the context in which Initialize() has been invoked, and the status of a strategy (e.g. started or not)?

    There appear to be a number of possible contexts in which Initialize() can be invoked, including:
    • When adding a strategy in the Strategies tab of the Control Center
    • When adding a strategy on a chart
    • When starting a strategy

    I know that one can check if a strategy has been started on a chart by checking if this.ChartControl is not null, indicating the strategy is active and was started on a chart.

    If one adds a strategy in the Strategies tab of the Control Center (not on a chart) and starts it, even though the strategy is active, this.ChartControl is (quite correctly) null and so cannot indicate if the invocation of Initialize() came as the result of starting a strategy or some other non-start context.

    The challenge is to determine when Initialize() has been invoked and in what context for all possible contexts and to be able to know the current status of a strategy.

    For example, using just this.ChartControl, one cannot distinguish between invocation of Initialize() when a strategy has not been started and when a strategy not on a chart has been started.

    This is significant when adding data series because OnStartUp() is not invoked until all data series are added, even though Initialize(), from where the series were Add'ed, will exit before all data series are added. So one cannot use OnStartUp() to determine if the strategy has been started or if Initialize() has been invoked in a non-start context.

    I would be most grateful for a way, albeit unsupported, to reliably know the invocation context and status of Initialize() and the current status of the strategy.

    Thanks!

    #2
    Hello jeronymite,

    There would not be a good way to determine this because Initialize() was designed to be called on all NinjaScript methods when first brought up and not to be called when a NinjaScript file was started.

    This is why OnStartUp() was created to be called once after a NinjaScript file has been ran.

    Are you trying to dynamically add a Data Series based on the Strategies status?
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks for your response.

      Within Initialize(), I want to know when the particular strategy has been genuinely started as opposed to other activities which would call Initialize(). Obviously, there is a distinction -- it's a matter of what (unsupported) variable or method will divulge that. Based on the circumstance, I take different actions.

      Also, if OnStartUp() were invoked immediately Initialize() exited, it would not be as great a concern. Unfortunately, OnStartUp() is not invoked until all consequential actions from Initialize() are completed. For example, all data series must be completely added, before OnStartUp() is invoked. Whilst logical in some senses, it means that when a large number of data series is added and it takes a long time, or there is any issue with the data feed that is not detectable by OnConnectionStatus(), the strategy effectively appears to be hung, even though it may be active doing data series downloads or some other activity.

      It is a "limbo" state like this example that I want to be able to detect. There are advantages to knowing the status of the strategy more generally, including how it has been invoked and if indeed it is active or not enabled and other "checking" activities are in progress.

      Also, for this particular example, I want to monitor the progress of the data series downloads programmatically.

      So, a number of programmatic capabilities are desirable:
      • Determine the origin of an invocation (the current context) of Initialize()
      • Have the option to progress to OnStartUp() asynchronously within background activities initiated from within Initialize() such as data series downloads
      • Be able to monitor the status of background activities such as data series downloads
      • Be able to synchronise with asynchronous background activities, when desired

      Most grateful for supported and unsupported means to do any/all of these things. If possible, please avoid the "not supported, can't help you" response, since many unsupported ways of doing things are discussed in these forums, and all necessary caveats associated with unsupported ways of doing things are extremely well understood and accepted. It is the willingness of NT Support to go outside the box at times (with appropriate caveats) that makes these forums so valuable. Similarly, for all the talented traders who likewise find ways to do unsupported but desirable things. Thanks!!

      As always, where these are not supported today in NT7, please also add them to the desired features list for NT8. Thanks!

      Comment


        #4
        Hello jeronymite,

        Thank you for your response.

        Can you provide some examples of when Initialize() is invoked that you wish to know in the strategy?
        Last edited by NinjaTrader_PatrickH; 10-14-2013, 08:43 AM.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your response, Patrick.

          The critical thing I want to know is simply this: Is Initialize() invoked because the strategy has been enabled/started, or because some other action has been taken that invokes Initialize() but does not enable/start the strategy.

          Beyond that, all the things mentioned in my followup post below are desirable.

          Thanks!

          Comment


            #6
            Hello jeronymite,

            Thank you for your response.

            There appears to be no way to tell what invoked the Initialize() method (whether strategy started, strategy menu opened, etc.). Even when debugging through Visual Studio the call stacks are identical for the Initialize() method.

            Please let me know if I may be of further assistance.
            Last edited by NinjaTrader_PatrickH; 10-14-2013, 10:54 AM.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Thanks for the update, Patrick.

              That is problematic, since there are many actions that seem to invoke Initialize() and one needs to be able to know the context of those invocations to be able to take appropriate actions or prevent inappropriate actions.

              Are there ways to obtain the context indirectly by knowing the status of the strategy? So, for example, is there something that says the strategy has been enabled, or restarted, etc?

              If that information is available (and accessible from Initialize()), one can infer the reason for invocation.

              Most grateful for your kind assistance.

              Comment


                #8
                Hello jeronymite,

                Thank you for your response.

                You can check if the strategy is enabled, but this is a little redundant as the strategy is already enabled if calling Initialize(), you would need some sort of previous state check like if previously enabled. I am not sure how that would be possible.
                Code:
                        protected override void Initialize()
                        {
                           	if(Enabled)
                			{
                				//Enabled
                			}
                Please let me know if I may be of further assistance.
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks, Patrick.

                  In all my testing, within Initialize(), Enabled is always false, no matter what the context of invoking Initialize() might be; so it is of no use in this instance.

                  The strategy (or strategy invocation engine) obviously knows whether it is calling Initialize() as part of an action that will result in the strategy being enabled or not and thus entering OnStartUp() or not -- that is the item I need to know.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by StevenNelson, Today, 12:29 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post StevenNelson  
                  Started by anupsoni, Today, 12:23 PM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Started by aligator, Yesterday, 12:15 PM
                  6 responses
                  60 views
                  0 likes
                  Last Post eDanny
                  by eDanny
                   
                  Started by frankduc, Today, 11:22 AM
                  3 responses
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by aslane, Today, 10:53 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X