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

Total Account Realized and Unrealized PnL with Commissions

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

    Total Account Realized and Unrealized PnL with Commissions

    Guys, I am trying to put limits in my NT7 strategies that will stop them from trading when my total account value, realized and unrealized, including commissions, reaches a maximum or minimum on the day. Is there a method (perhaps unsupported) to determine this information across all running strategies on a given account in NT7? The total account realized+unrealized value including commissions? GetAccountValue(AccountItem...) has only a few options, and none contain this important information.

    Thank you for your help!

    Best wishes,

    Light

    #2
    Hello Light,
    Thanks for your post.

    Yes, it is possible to stop your strategy from trading after the unrealized, realized, or unrealized+realized reaches a certain amount. This would require that you code this into your script with logic by looping through the orders collection. Please see the following links for two examples on how to create a daily stop loss for your strategy.

    DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241

    DailyLossLimitMultiTradeExample_NT7 - http://ninjatrader.com/support/forum...367#post475367

    Please let me know if you have any questions.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the note Josh. I have read through Chelsea's zip files in your response and to my knowledge they will not be of use for the problem I described. Isn't the Performance method specific to each strategy alone? I am seeking the current unrealized+realized+commission value for the entire account, summing all running strategies combined, even when those strategies are running on different markets and different charts. For example, suppose I have three strategies running on three different markets, each with their own chart, and all three have open positions. How do I find the total unrealized profit + realized profit + commissions for all three strategies combined -- in other words, for the Account as whole, in total? NT7's Market Analyzer has this information, and in principle, GetAccountValue(AccountItem.CashValue) would contain its equivalent, if this value were updated every tick on all open positions. But I see no simple way to obtain this information in NinjaScript. Have I missed something, or misunderstood?

      Thank you again for your help,

      Best wishes,

      Light

      Comment


        #4
        Hello Light,

        Thank you for the reply.

        It is not supported to access the account information in NinjaTrader 7, but here is an example of doing so:



        In NinjaTrader 8, accessing account information is fully supported through the Account class.

        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris, a quick question:

          is the method " GetAccountValue()" totally reliable working with the real InteractiveBroker account?

          Thanks!




          Comment


            #6
            Hello pstrusi,

            Thank you for the post.

            I was able to get Interactive Brokers account values with GetAccountValue. I have attached a test script that you can use, it will only print to the Output window and not place any trades.

            Please let me know if I can assist further.
            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              I use a multi-instrument strategy with 34 added instruments and kinetick and IB connections. Does not print... Ideas why? Regards and many thanks guys.


              Print("Open PnL: " + PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Currency, Close[0]));

              Comment


                #8
                With so little information to gone on, my best idea is this:
                You're probably doing something wrong somewhere in your code.

                Seriously, how is anyone supposed to have any 'ideas'
                with such a minimal description?


                Does your strategy take any trades?
                Where is the above 'Print' statement being executed from?
                Any error messages in the Log tab?
                Are you taking trades in all 34 instruments, or just one or two?
                Has this strategy ever worked before?
                I mean, how new is this Print statement relative to the rest of the code?

                I can think of dozens of questions ...

                And finally:
                You should probably have started a new thread so that it could be
                dedicated to your specific issue ... IMHO, hijacking previous threads
                is not the best way to introduce new private issues, even if they are
                somewhat related. I know NT support prefers new threads for
                new issues.

                Comment


                  #9
                  Hi elliot5, thanks for your question.

                  Make sure the Print statement is actually being called, add another Print Statement above to confirm this.

                  To keep things organized, use these Print statements in only one of the BarsInProgress indices e.g.

                  Code:
                  OnBarUpdate()
                  {
                      if(BarsInProgress == 0)
                      {
                  
                          Print("About to check Account UnrealizedProfitLoss");
                          Print("Open PnL: " + PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]));
                  
                      }
                  }
                  If you are seeing the first print but no print for the second statement, check the log tab of your Control Center for errors, and please provide some more details on how GetUnrealizedProfitLoss is used in the script.

                  Kind regards.

                  Chris L.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by yertle, Today, 08:38 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post yertle
                  by yertle
                   
                  Started by Mestor, 03-10-2023, 01:50 AM
                  15 responses
                  378 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by samish18, Yesterday, 08:57 AM
                  10 responses
                  27 views
                  0 likes
                  Last Post samish18  
                  Started by matty89, 03-02-2020, 08:31 AM
                  34 responses
                  3,039 views
                  1 like
                  Last Post NinjaTrader_BrandonH  
                  Started by kujista, Today, 05:44 AM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X