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

GetUnrealizedProfitLoss() of another account

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

    GetUnrealizedProfitLoss() of another account

    Strategy A is running on account Sim101 and
    Strategy B is running on account Sim102

    Can Strategy A GetUnrealizedProfitLoss()
    of Sim102?

    #2
    Hello johnnybegoode,

    You can use the PositionsAccount object to find account positions. With a PositionAccount object, you can then use the standard GetUnrealizedProfitLoss() to get PnL.





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

    Comment


      #3
      I would like to get a total of the Unrealized PnL
      of Sim101 and Sim102,

      Strategy A is buying EUR/USD on Sim101 account and
      Strategy B is selling EUR/USD on Sim102 account.

      Does this look right?
      I keep getting the DB error (attached)

      Strategy A is enabled on Account Sim101
      Code:
      else if (State == State.Configure)
                  {
                      AddDataSeries("EURUSD", Data.BarsPeriodType.Second, 1, Data.MarketDataType.Last);[B] // is this for Sim102?[/B]
                  }

      Code:
      double Profit =
                      (
                      PositionsAccount[0].GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) // [B]is this Sim101?[/B]
                       +
                      PositionsAccount[1].GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) // [B]and this is Sim102?[/B]
                      );

      Strategy B is enabled on Account Sim102
      Code:
      else if (State == State.Configure)
                  {
                      AddDataSeries("EURUSD", Data.BarsPeriodType.Second, 1, Data.MarketDataType.Last); [B]// is this for Sim101?[/B]
                  }

      Code:
      double Profit =
                      (
                      PositionsAccount[0].GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) // [B]is this Sim102?[/B]
                       +
                      PositionsAccount[1].GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) // [B]and this is Sim101?[/B]
                      );
      Attached Files
      Last edited by johnnybegoode; 04-03-2019, 10:18 PM.

      Comment


        #4
        Hello johnnybegoode,

        Thank you for your reply.

        What you provided would not be correct, a strategy can only reference a single account at once. What you are asking for would require using the addon account methods to locate the second account. Your strategy and its properties will only reference the account you applied it to when you enabled it. Strategies are really not intended to access any values besides their own, they are intended to be isolated so all properties and methods a strategy has will only apply to what it has done its self and the account it selected.

        You could use the addon account methods to pull the overall account values from an account.

        https://ninjatrader.com/support/helpGuides/nt8/en-us/?get.htm

        https://ninjatrader.com/support/helpGuides/nt8/en-us/account_class.htm



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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        12 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        7 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        6 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X