Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

execution.Order.GetOwnerStrategy(); returns null

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

    execution.Order.GetOwnerStrategy(); returns null

    Hello. I am calling static methods from OnExecutionUpdate to handle email notification and db logging. I don't want to pass the strategy as a parameter using "this" so I am using execution.Order.GetOwnerStrategy() but it returns null on exiting a position.

    thanks

    #2
    Hello [email protected], and thank you for your question. I couldn't find any documented method called GetOwnerStrategy in the help guide, is this a method you or another programmer wrote?

    If you would like a "this" reference available to static calls, you can use a static member such as

    Code:
    private static Strategy self;
    You can then assign this to self during State.SetDefaults .

    If you would like to do this in another thread (for example, from another strategy), then you will need to use a Dispatcher, publicly available documentation https://msdn.microsoft.com/en-us/lib...ispatcher.aspx .

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      This is an example of a method signature I am using:

      public static void SendMailonExit(Execution execution)
      {
      var sgn = (execution.Order.OrderAction == OrderAction.BuyToCover ? 1 : -1);
      var strategy = execution.Order.GetOwnerStrategy();
      var state = strategy.State;
      var account = strategy.Account;
      var performance = strategy.SystemPerformance;

      Comment


        #4
        Hello [email protected],

        Thank you for your response.

        GetOwnerStrategy() is not a supported method for Order. Any reason you do not wish to pass through "this" for the strategy?

        I look forward to your response.

        Comment


          #5
          I can use "this" is that is the supported approach.

          thanks

          Comment


            #6
            You can define your method signature to support any approach you would prefer. A signature that would accept a "this" reference may be

            Code:
            	public static void SendMailonExit(Strategy strategy, Execution execution)
            You can then pass "this" in as your first argument, and then have access to the calling strategy via the strategy object.
            Jessica P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            67 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            142 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            76 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            47 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            51 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X