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

Addons and UnrealizedProfitLoss real time value

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

    Addons and UnrealizedProfitLoss real time value

    Hi team,

    I have an Addon monitoring a specific account. I register to account events on both AccountItem and PositionUpdates to listen for account value changes.

    I am interested in getting the real time unrealized value, but AccountItem.UnrealizedProfitLoss and position.GetUnrealizedProfitLoss() donīt seem to provide real time changes of the account, or at least not for UnrealizedProfitLoss​ values.


    ​How can I get the UnrealizedProfitLoss value in Real Time using an addon (not in a strategy)?

    If you can provide an example on how to do this would be really nice.

    Thanks!

    #2
    Hello juartur,

    If you are using OnPositionUpdate from the account that specifically does not provide a position object and generally would not be a good location to drive realtime updates. You could insead run logic in OnBarUpdate if you wanted to continuously get realtime values.

    In normal addon use cases you would use the OnPositionUpdate event and use the values it passed in. The average price is passed in which you would then store to a variable so you can at any point recalculate the pnl based on that price.



    For example for position update events you would use the PositionEventArgs object:

    Code:
    private void OnPositionUpdate(object sender, PositionEventArgs e)
    {
        // Output the new position
        NinjaTrader.Code.Output.Process(string.Format("Ins trument: {0} MarketPosition: {1} AveragePrice: {2} Quantity: {3}",
    e.Position.Instrument.FullName, e.MarketPosition, e.AveragePrice, e.Quantity), PrintTo.OutputTab1);
    }
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse

      Thanks for your prompt reply.

      So OnPositionUpdate isnīt the place to catch realtime updates in an addon, therefore OnPositionUpdate cannot be used for that purpose either.

      I suppose I can also use OnMarketData() in the addon to get on tick updates, but how do I get the realtime unrealized value of the account? do you have an example of that?

      Correct me if Iīm wrong but I understand that within a strategy you define a specific account and it is not possible to get real time updates of other accounts in the same strategy, at least I couldnīt make that work. For that reason I try to use an addon to get the real time updates of say 2 different accounts.

      If itīd be possible to get updates of different accounts in the strategy itself then great, but is it?

      Thanks


      Comment


        #4
        Hello juartur,

        OnPositionUpdate gets the position update events when something changes, while you can observe changes in realtime its not going to provide continuous updates to keep a value updated. If you wanted to do that you need to use a method that is called frequently like OnBarUpdate or OnMarketData and then use a position object and its GetUnrealizedProfitLoss method or store the average price you had observed in OnPositionUpdate and manually calculate the value.

        You can use the Account.Get method to get account values, you would use that logic from OnBarUpdate or OnMarketData to get continuous updates. https://ninjatrader.com/support/helpGuides/nt8/get.htm

        Strategies can only operate on 1 account at a time so an indicator could be used with the addon framework if you wanted to make a tool that uses more than one connected account.




        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        9 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        14 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        13 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,983 views
        3 likes
        Last Post jhudas88  
        Working...
        X