Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnPositionUpdate Only Called for Strategy on Chart?

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

    OnPositionUpdate Only Called for Strategy on Chart?


    Hi there team,

    I wrote a base strategy class called StrategyLogger that aims to log the PnL of each trade to a CSV file. My plan is to use this only as a base class, and have my actual strategies that will be running live extend this base class and inherit this CSV writing capability.

    The base class overrides OnPositionUpdate() and has some logic in it to begin writing the file header and each line of the file.

    A problem I'm running into is this: It seems that this only works with strategies running on a chart. That is, a custom strategy that I create that extends StrategyLogger will ONLY write to the CSV file if it's running on a chart. If I run the same strategy via the Strategies tab, nothing happens.

    Why is this?

    I've attached 2 files below. One is the basic idea of the StrategyLogger class itself, and another is a simple example strategy that I wrote to illustrate the issue. I run it on a 10 second chart so as to not waste any time and get can get errors, print logs (or no results) quickly.

    After doing some debugging with Print statements, it seems the OnPositionUpdate() function is not being called when the strategy is running via the strategies tab, but is being called when the strategy is running on the chart? I had another developer tell me that this is because OnPositionUpdate() is only called within the context of an associated account, and an account is known during chart trading, but no account is known when running via the Strategies tab. This made no sense to me, but still including here to confirm.

    Can anyone take a look at the 2 files I've shared below and let me know if the issue is in the code, or there is some other NinjaTrader quirk we are missing?


    - Jay
    Attached Files
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    Hello jaybedreamin,

    The OnPositionUpdate, OnOrderUpdate, and OnExecutionUpdate overrides only update for orders placed by that strategy instance. These do not update from other strategies.

    If you want to run logic when an Account position or order updates, you would need to do this by attaching handler methods to the <Account>.PositionUpdate / <Account>.ExecutionUpdate events using the Addon approach.

    Below are links to the help guide.



    From the Strategies tab, the OnPositionUpdate override will still be triggering, but only for that strategies position.
    Further, the Account is selected in the strategy parameters, even when running the strategy from the Strategies tab of the Control Center.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi there and thanks for the response NinjaTrader_ChelseaB . I actually don't think that's correct, because we wrote that exact same architecture before and it was working.

      Base class Strategy A
      Strategy B extends base class Strategy A, in OnPositionUpdate of Strategy B call base.OnPositionUpdate() and it works fine. OnPositionUpdate() of Strategy B gets called and printed to the logs.

      The problem I expressed in the OP is that this seems to work when Strategy B is applied to a chart, but not from the strategies tab and I was attempting to figure out why.
      jaybedreamin
      NinjaTrader Ecosystem Vendor - Zion Trading Algos

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X