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

Account level Realized and Unrealized

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

    Account level Realized and Unrealized

    Hello,

    Is it possible to read what the total realized gain/loss and unrealized for the Account (not individual strategy) is?

    I'm trying to set a max daily loss for the account for all strategies. I'm thinking I can create a condition in each strategy to only take trades if realized + unrealized > X, where X is my max daily loss.

    If there's any other way to set up a max loss, please let me know.

    Any help would be appreciated.

    Thanks,

    Pete

    #2
    Hi Pete,

    Thank you for your note.

    There is a method to be able to access the Account information, Please note that the method is unsupported and would not be able to offer assistance or debugging issues for it.
    Code:
    foreach (Account acct in Cbi.Globals.Accounts)
    {
    if (acct.Positions != null)
    {
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
    }
    }
    Let me know if there is anything else I can assist with,
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your response. This code only prints out what open positions are, with no reference to realized or unrealized data.


      I tried GetAccountValue this morning to get the net liquidation value at the open of trading, but it returns 0. Any other ideas?



      Originally posted by NinjaTrader_Cal View Post
      Hi Pete,

      Thank you for your note.

      There is a method to be able to access the Account information, Please note that the method is unsupported and would not be able to offer assistance or debugging issues for it.
      Code:
      foreach (Account acct in Cbi.Globals.Accounts)
      {
      if (acct.Positions != null)
      {
      PositionCollection positions = acct.Positions;
      foreach (Position pos in positions)
      {
      Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
      }
      }
      Let me know if there is anything else I can assist with,

      Comment


        #4
        PeteM,

        As I stated previously, this is all unsupported with NinjaTrader. The code I gave you was an example of how to obtain the account. This sample is getting the position. You might be able to adjust it to work for getting the Unrealized PnL and realized PnL from the trade collection setup -
        http://www.ninjatrader.com/support/h...collection.htm
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the link, I'll play with that later.

          Any idea on why the GetAccountValue code returns 0? I know it needs to work in real time so I set it to wait until market open to get the net liq value. Still returns 0.


          Originally posted by NinjaTrader_Cal View Post
          PeteM,

          As I stated previously, this is all unsupported with NinjaTrader. The code I gave you was an example of how to obtain the account. This sample is getting the position. You might be able to adjust it to work for getting the Unrealized PnL and realized PnL from the trade collection setup -
          http://www.ninjatrader.com/support/h...collection.htm

          Comment


            #6
            What's the full coding that you use for the GetAccountValue()?
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              openingBalance = GetAccountValue(AccountItem.NetLiquidation);
              Print("Account Opening Net Liq = " + openingBalance);

              Comment


                #8
                Pete,

                Apologies I forgot to include -

                Who are you connected to? This is displayed in the lower left hand corner of the Control Center
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Interactive Brokers



                  Originally posted by NinjaTrader_Cal View Post
                  Pete,

                  Apologies I forgot to include -

                  Who are you connected to? This is displayed in the lower left hand corner of the Control Center

                  Comment


                    #10
                    Pete,

                    The IB Connection supports Net Liquidation By Currency.

                    Try using -
                    Code:
                    GetAccountValue(AccountItem.NetLiquidationByCurrency);
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Still showing 0.

                      If my connection is IB, but I'm simulating the strategy, should it return the IB value or the Sim account value?

                      Or does this not work unless I'm not in simulation?



                      Originally posted by NinjaTrader_Cal View Post
                      Pete,

                      The IB Connection supports Net Liquidation By Currency.

                      Try using -
                      Code:
                      GetAccountValue(AccountItem.NetLiquidationByCurrency);

                      Comment


                        #12
                        Pete,

                        This value will only be reported by IB for the Live account. This type of value will not be available for the Sim101 account.
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          You are correct. Just tried strategy on IB account and it works.

                          Thanks for your help Cal.


                          Originally posted by NinjaTrader_Cal View Post
                          Pete,

                          This value will only be reported by IB for the Live account. This type of value will not be available for the Sim101 account.

                          Comment


                            #14
                            Account level max loss/profit

                            Is there any way to access the current daily profit or loss at an account level across all strategies? This would be calculated on all closed trades, so on on realized profit and loss. I want to do this for CQG and for SIM accounts. I want to build a feature in my strategies that halts all trades based on a max loss or profit level for the account. Thanks.

                            Comment


                              #15
                              rdesilva, welcome to our forums - the individual scripts would not cross communicate, so one way would be working for example in a Multi series script to be able to cumulate. Or you would work via the Account level offered items through GetAccountValue as discussed in this thread already

                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, 04-19-2024, 09:40 AM
                              8 responses
                              53 views
                              0 likes
                              Last Post alifarahani  
                              Started by mmckinnm, Today, 01:34 PM
                              2 responses
                              4 views
                              0 likes
                              Last Post mmckinnm  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              3 responses
                              60 views
                              0 likes
                              Last Post NinjaTrader_SeanH  
                              Started by f.saeidi, Today, 01:32 PM
                              1 response
                              2 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by traderqz, Today, 12:06 AM
                              9 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X