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

Bug: AccountItemUpdate doesn't fire on bind

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

    Bug: AccountItemUpdate doesn't fire on bind

    I've got various different controls who need to know about account item updates.

    In the attached example, I'm switching accounts using the account switcher from chart trader. Unbinding existing handlers from the old account, and rebinding them with the new account.

    The problem is, that even though the account values have changed (the new account has different values from the old account). The controls never get the update as the OnAccountItemUpdate doesn't fire when it is first bound to; unlike the MarketData event, which provides the current data when a new handler binds to it.
    Attached Files

    #2
    Hello,

    Thank you for the post.

    While I am unable to see the OnAccountItemUpdate not working, I do see that you are not correctly unsubscribing from the previously selected account leaving multiple handlers subscribed. In the sample, you are only checking that the account which will be subscribed to does not have a current handler, this does not unsubscribe from the previously subscribed account leading to unwanted subscriptions.

    I have included a sample which correctly subscribes and unsubscribes from an account, could you review this and see if you are still unable to see the correct OnAccountItemUpdate action or if it gets called? Please Disable/remove the script you had provided to prevent it from working the next time you open a chart, then restart the platform. Next import the attached zip file. The restart is crucial to remove the handlers which will not be removed based on your example. To test this on my end I had placed an order and then closed the position to see that the account gets updated.

    Here is sample output from running the attached script:

    Added OnPositionUpdate handler to Sim101
    //placed an order and closed the position
    Sim101 got AccountItem update: CashValue 1111217.49999999
    Sim101 got AccountItem update: ExcessIntradayMargin 1111217.49999999
    Sim101 got AccountItem update: ExcessInitialMargin 1111217.49999999
    Sim101 got AccountItem update: ExcessMaintenanceMargin 1111217.49999999
    Sim101 got AccountItem update: ExcessPositionMargin 1111217.49999999
    Sim101 got AccountItem update: GrossRealizedProfitLoss -3.00000000000047
    Sim101 got AccountItem update: RealizedProfitLoss -3.00000000000047
    Sim101 got AccountItem update: LongStockValue 0
    Sim101 got AccountItem update: NetLiquidation 1111217.49999999
    Sim101 got AccountItem update: RealizedProfitLoss -3.00000000000047
    //changed the selected account
    Removed OnPositionUpdate handler from Sim101
    Added OnPositionUpdate handler to account23
    //placed an order and closed the position
    account23 got AccountItem update: CashValue 98293
    account23 got AccountItem update: ExcessIntradayMargin 98293
    account23 got AccountItem update: ExcessInitialMargin 98293
    account23 got AccountItem update: ExcessMaintenanceMargin 98293
    account23 got AccountItem update: ExcessPositionMargin 98293
    account23 got AccountItem update: LongStockValue 1707
    account23 got AccountItem update: CashValue 99999
    account23 got AccountItem update: ExcessIntradayMargin 99999
    account23 got AccountItem update: ExcessInitialMargin 99999
    account23 got AccountItem update: ExcessMaintenanceMargin 99999
    account23 got AccountItem update: ExcessPositionMargin 99999
    account23 got AccountItem update: GrossRealizedProfitLoss -1.00000000000016
    account23 got AccountItem update: RealizedProfitLoss -1.00000000000016
    account23 got AccountItem update: LongStockValue 0
    account23 got AccountItem update: NetLiquidation 99999
    account23 got AccountItem update: RealizedProfitLoss -1.00000000000016

    I look forward to being of further assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hey Jesse,

      Thanks for the response. I can't see how I'm not unsubscribing in the example I sent, from what I can see your code does the same as mine.

      Anyway, that's not the issue. Yes, the event fires when new changes come in. However, unlike most other Ninjatrader data handlers, (MarketData, MarketDepth, Fundamentals etc) which all fire immediately when a new handler subscribes to provide it with the current state.... the AccountItemUpdate event does not do this. It means when I switch accounts, and bind to the new handler - everything that uses the data still has the data for the old account; until a change comes in.

      I can get around it by manually grabbing the account data after I've subscribed. But its just annoying having to duplicate code when the other handlers don't require this. In strict semantic terms, going from a state of not having data, to a state of having data would constitute an update, so events like this should fire immediately on subscription.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Christopher_R, Today, 12:29 AM
      0 responses
      9 views
      0 likes
      Last Post Christopher_R  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      166 responses
      2,235 views
      0 likes
      Last Post sidlercom80  
      Started by thread, Yesterday, 11:58 PM
      0 responses
      3 views
      0 likes
      Last Post thread
      by thread
       
      Started by jclose, Yesterday, 09:37 PM
      0 responses
      8 views
      0 likes
      Last Post jclose
      by jclose
       
      Started by WeyldFalcon, 08-07-2020, 06:13 AM
      10 responses
      1,415 views
      0 likes
      Last Post Traderontheroad  
      Working...
      X