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

Subscribing to Strategy Order/Execution updates by delegate

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

    Subscribing to Strategy Order/Execution updates by delegate

    The account class lets us subscribe to OnOrderUpdate and OnExecutionUpdate etc via an event delegate

    e.g. https://ninjatrader.com/support/help...rderupdate.htm

    Code:
    account.OrderUpdate += OnOrderUpdate;
    Is it possible to do the same for a Strategy?


    #2
    Hello kevinenergy,

    When working with a strategy you would have the override methods instead of event handlers that can be used within the strategies code. You would need to utilize the Account class if you wanted to subscribe to the events of the account directly. The platform and its internal logic would filter relevant internal events related to that script and then would supply that information to your script by calling its overrides. because this is an override method and not an event, an outside script would be unable to subscribe to the strategies events specifically.



    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hey Jesse, thanks for the response.

      The problem I've got, is that if I subscribe to the OnOrderUpdate or OnExecutionUpdate events via the Account class, the events don't get fired during the Strategy's historical data processing. This means that my unmanaged order handling is totally broken and my strategy starts in a very corrupted state.

      The events do fire during realtime processing though. Possibly a bug?

      Not an ideal situation because I spent a lot of time writing an unmanaged order handling system, I would ideally like to share this between multiple strategies by instantiating the unmanaged order handler in the strategy and subscribing to the events it needs. But the way things are presently it looks I need to duplicate all of the order handler code between every strategy that uses it.

      Comment


        #4
        Hello kevinenergy,

        This is not a bug this is how the account class should work. In this case, you are mixing two separate concepts of the Addon account methods which interface directly with the account and the virtual strategy methods which do not directly interface with the account.

        In general, the addon account methods are only intended for complex tools that are not specifically strategies, for example, if you wanted to make your own DOM tool for manual trading that applies some extra logic. Strategies are intended to work as a virtual entity which is loosely associated with the account in a virtualized way. Strategies are also intended to isolate performance away from the overall account and give the ability to backtest in the analyzer. The Addon account methods would not be for these virtualized uses.

        The short solution here is to avoid using a strategy if you want to use the account class for order handling. In that situation, you could use the account class to both observe and submit orders to avoid the virtualization problem. If you want to use specifically a strategy, I would suggest avoiding using the account class as you will run into roadblocks like this where the concepts do not match together in a way that would work correctly.

        The historical trades a strategy produces are virtual and not being sent to the Account as live trades, you will see that the control center does not display these historical trades. The Account class would really only be useful for real-time trading or actual events that are sent to the selected account such as a manual trade. If you are trying to use the historical backtest information from the strategy that logic would generally need to go inside of the strategy where the virtual properties apply. You may be able to use the strategies trade collections but in general, I wouldn't suggest trying to mix the virtual and real information and instead use one or the other.

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by geddyisodin, Yesterday, 05:20 AM
        7 responses
        45 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by gbourque, Today, 06:39 AM
        2 responses
        5 views
        0 likes
        Last Post gbourque  
        Started by cre8able, Yesterday, 07:24 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by cocoescala, 10-12-2018, 11:02 PM
        6 responses
        939 views
        0 likes
        Last Post Jquiroz1975  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X