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

Recalculating position size based on account size, % risked and stop loss

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

    Recalculating position size based on account size, % risked and stop loss

    Does anyone know how to program NT so that when you backtest a system Ninjatrader recalculates the No. of contracts for each entry based on your current account size, % of account risked and your stop loss.
    For example I trade with an account
    > size of say $100,000 but only use a percentage of this per trade say
    > 5% or $5000. To calculate the no of contracts traded for the Emini ES
    > at $50/point and say 7pt stop loss with 5% of $100,000 = 5000/(7x50)
    > which approximately equals 14 contracts. (I guess the calculation has
    > to round down to the nearest integer too)! As my account goes up, so
    > should the No. of contracts traded which compounds your account. How do I do this?

    > Thanks in advance
    >
    > Clive
    Last edited by clivehunt; 02-05-2008, 10:19 AM.

    #2
    You would have to code your math logic in NinjaScript and calculate the "quantity" value which you could shift into the various Enter... methods.

    Comment


      #3
      Hello Dierk and thanks to clivehunt for the question.

      What would be the basic command for calling up the present account value so that it could be used in the way that clivehunt suggests. The account value would change after every trade and so the number of contracts would be adjusted accordingly per the math used. I use Interactive Brokers and NT 6.

      Thanks,
      dendy.

      Comment


        #4
        You can use AccountSize along with Performance to get what you want.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh for the reply,

          From what I can tell, AccountSize will not give the Account Value but only allow one to specify the value as such:

          protected override void Initialize()
          {
          AccountSize = 10000;
          }
          I am searching for a way that this can happen automatically by pulling in my actual account value and then allowing the type of mathematics that clivehunt talked about to do the rest.

          Are you suggesting that this value cannot be obtained and by manually entering the AccountSize I can still calculate my values without NT6 automatically calculating my lot size for me based upon my entered margin requirements.

          Thanks again for the help.

          dendy.

          Comment


            #6
            Pulling in the actual account value is not supported at this time.
            RayNinjaTrader Customer Service

            Comment


              #7
              Thanks for the response Ray,

              Do the following Perfomance commands work for the current NT6 session only? (I'm defining session as the time between NT6 start-up and shut-down.) Let's say we start NT6 in the morning and lose $1000 on short trades and make $1500 on long trades, will the "Performance.AllTrades.Performance.Currency.CumPro fit" give the Cumulative Profit for the day only as $500? Does it care if the orders were entered by a strategy or manually or from the DynamicSuperDOM?

              protected override void OnBarUpdate()
              {
              // Print out the maximum number of consecutive losing trades on all trades
              Print(Performance.AllTrades.Performance.MaxConsecL oser);
              // Print out the avg trade duration for winning long trades
              Print(Performance.LongTrades.WinningTrades.Perform ance.AvgTradeDuration);
              // Print out the realized profit in currency for all trades
              Print(Performance.AllTrades.Performance.Currency.C umProfit);
              }
              Thanks for the help,
              dendy.

              Comment


                #8
                PnL relative to the strategy only and for the history of the strategy. If it only contained real-time trades then it would be for real-time only of course.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Thanks Ray,

                  I think that what you're saying is that any trade made during the time the strategy is running will be picked up by these "Performance" commands and used in the strategy. Is there any way to make the "Performance" command only work for the trades entered by the strategy in which it resides?

                  For example,
                  I'm running a real time strategy (using real money) with the "Performance" command for Cumulative Profit. I then start up a strategy analyzer and run another strategy against historical data. This back tested strategy produces significant income. Does this back tested run have to impact the real time strategy's "Performance" command, or is there some way to insulate the strategy so that it does not pick up this other data?

                  Thanks,
                  dendy.

                  Comment


                    #10
                    Thats not what I am saying. What you want is how it works. Only trades generated by the strategy are included.
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks again Ray,

                      I believe it is clear to me now.

                      dendy.

                      Comment


                        #12
                        Hi,

                        I have a question about:

                        Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit

                        Suppose in Week 1, I first started running Strategy A on EURUSD, GBPUSD, USDCHF and USDJPY at the same time. At any time the above code is called, can I confirm that the cumulative profits is that of the realised profits/losses arising from Strategy A of the four pairs combined?

                        At the end of Week 1, I closed NinjaTrader and switched off my computer. At the start of Week 2, I powered up my computer, opened NinjaTrader and continued running Strategy A on EURUSD, GBPUSD, USDCHF and USDJPY. Can I confirm that the above code will include cumulative profits of both Week 1 and Week 2?

                        Comment


                          #13
                          No, you would need to leave your strategy running to keep performance of your realtime trades accurate. Performance is NOT recalculated from the historical trades as you restart the strategy.

                          Comment


                            #14
                            Hi Dierk,

                            Thanks for your reply.

                            With regards to the situation when Strategy A is run across four currency pairs, Performance will be the cumulative realised profits of all four pairs?

                            Comment


                              #15
                              That is correct.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by warreng86, 11-10-2020, 02:04 PM
                              4 responses
                              1,354 views
                              0 likes
                              Last Post mathewlo  
                              Started by Perr0Grande, Today, 08:16 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Perr0Grande  
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post maybeimnotrader  
                              Working...
                              X