• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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

                              http://www.ninjatrader.com/support/h...countvalue.htm
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by digibob, Today, 03:45 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by waldoalvarez, Yesterday, 04:59 PM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by jayfutures23, Today, 07:06 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Melissa  
                              Started by MojoJojo, Today, 05:59 AM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Spark68, Yesterday, 07:48 PM
                              1 response
                              19 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Working...
                              X