Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position Size Algorithm

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

    #16
    Originally posted by titleistbb22 View Post
    PrTester - Thank you for the post. I think your solution is a sensible work around to the account size problem. However I am struggling to make some modifications to your strategy. Ninja is giving me the following error

    **NT** Error on calling 'OnExecution' method for strategy 'DC1/24727490b1624fa4877b2ef3ad9108c9': Object reference not set to an instance of an object.

    I am using OnExecution with the position entry

    entryOrder=EnterLong((int)Psize, "long1");

    Do you think this is causing the problem? If not I can post the full code. Thank you


    To clarify - this error was in the output window. The strategy does complie (if that helps anyone think of a solution)

    Thanks

    Comment


      #17
      Best thing to do would be to try and use try-catch blocks and isolate out exactly which line of code is causing the message.

      Please see an example of using try-catch blocks here: http://www.ninjatrader.com/support/f...ead.php?t=9825
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        In case there is any interest I did make this work. I simply placed the entry code inside of "{ }" similar to the sample code.

        My previous code did not make use of these brackets.

        Thank you





        Comment


          #19
          Revisiting this thread - as previously mentioned I did get this to execute properly, well at least it appeared that way. Now I do not feel the CumProfit feature is calculating correctly. Here is the position size coding I wrote (note: my start account size is 1mm).

          #region PositionSIzeFunction
          void PositionSize()
          {
          priorTradesCount = Performance.AllTrades.Count;
          priorTradesCumProfit = (
          double)Performance.AllTrades.TradesPerformance.Currency. CumProfit;
          AccbalNew = AccountSize + priorTradesCumProfit;

          if (AccountSize >= 900000)
          {
          Psize = ((AccbalNew*
          .02)/ ((ATR(20)[0]*2)*(pips)*(pipvalue))) ;
          if (Psize > 1 && usemoneymgt)
          Psize = Math.Round(Psize);
          else
          Psize = 1;
          }
          if (AccountSize <= 800000)
          {
          Psize =
          .8*(((AccbalNew*.02)/ ((ATR(20)[0]*2)*(pips)*(pipvalue)))) ;
          if (Psize > 1 && usemoneymgt)
          Psize = Math.Round(Psize);
          else
          Psize = 1;
          }

          The critical piece is the reduction in position size based on account balance. However my first trade on GBPJPY is a short and a loser (open price 140.66, close 146.27, position size 1 which I assume is a standard lot). Based on my math (pip cost = $120, pip loss 561 (146.27-140.66), $561*$120) the loss should be around $67k.

          Now take a look at the results in the output window.

          ACC BAlNew: 1000000
          Time: 4/27/2009 4:00:00 PM
          CumProfit: 0
          Position SIze: 1
          entry Price is: 140.66 on 4/28/2009 4:00:00 PM
          ACC BAlNew: 438600
          Time: 5/22/2009 4:00:00 PM
          CumProfit: -561400
          Position SIze: 1
          entry Price is: 150.57 on 5/25/2009 4:00:00 PM

          The CumProfit is neg 561k?! What am I missing? Is 1 quantity size larger that a standard lot? My account connection is gain, if that has anything to do with it.

          Thank you in advance for exploring this.

          Comment


            #20
            titleistbb22, I think the fact the CumProfit for the first losing trade is negative is ok, however I agree the raw # seems off - normally in backtesting for FX spot you would enter 100000 for a regular 100K lot. What instrument setup are you using in the Instrument Manager for the GBPJPY?
            BertrandNinjaTrader Customer Service

            Comment


              #21
              Thank you for the response - here is the data in the instrument manager for GBPJPY

              Point Value: 1,000
              Margin Value: 400
              TickSize: .001

              Comment


                #22
                Hello,

                I will have someone reply to you on Monday. Thank you for your patience.
                DenNinjaTrader Customer Service

                Comment


                  #23
                  Originally posted by titleistbb22 View Post
                  Thank you for the response - here is the data in the instrument manager for GBPJPY

                  Point Value: 1,000
                  Margin Value: 400
                  TickSize: .001
                  Can you please retry with a TickSize of 0.01 and then restart your NT fresh after this change to the master instrument?

                  Thanks
                  BertrandNinjaTrader Customer Service

                  Comment


                    #24
                    Thank you - tried this, here are the results. Still very large P&L on each trade

                    ACC BAlNew: 1000000
                    Time: 5/5/2009 4:00:00 PM
                    CumProfit: 0
                    Position SIze: 3
                    entry Price is: 149.05 on 5/6/2009 4:00:00 PM
                    ACC BAlNew: 54999.9999999983
                    Time: 5/22/2009 4:00:00 PM
                    CumProfit: -945000.000000002
                    Position SIze: 1
                    entry Price is: 150.55 on 5/25/2009 4:00:00 PM

                    I am expecting 11,340 loss (Entry 149.05, exit 145.90 - 315 pips. Cost per pip 12, position size 3)

                    Any thoughts? Thank you

                    Comment


                      #25
                      titleistbb22, I agree - what values are you getting if you manually place 3 lot trade on the sim account for the GBPUSD? Would that be according to what you expect?
                      BertrandNinjaTrader Customer Service

                      Comment


                        #26
                        Works - GBPUSD, enter 1.6699 long, exit 1.6377. 322 pips at $10 a pip * position size of six = 19,332 loss. Ck out the Cum Profit

                        ACC BAlNew: 1000000
                        Time: 9/10/2009 4:00:00 PM
                        CumProfit: 0
                        Position SIze: 6
                        entry Price is: 1.6699 on 9/11/2009 4:00:00 PM
                        ACC BAlNew: 980668
                        Time: 9/24/2009 4:00:00 PM
                        CumProfit: -19331.9999999999
                        Position SIze: 6
                        entry Price is: 1.5964 on 9/28/2009 4:00:00 PM

                        any thoughts on why JPY wont work? I tested this on EURJPY and got similar results to GBPJPY. The instrument settings for EURJPY are as follows

                        Point value 1,000
                        Tick size .001

                        Comment


                          #27
                          titleistbb22/Bertrand, Is it possible the CumProfit is being reported in yen instead of usd?
                          The Trading Mantis
                          NinjaTrader Ecosystem Vendor - The Trading Mantis

                          Comment


                            #28
                            We checked into matters and unfortunately you're running into a current limitation converting to USD, the realtime results are amended by the current conversion rate, while unfortunately this will not work on historical backtesting data.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #29
                              Thank you for looking into this. What does the future hold for Ninja and money managment / position sizing?

                              Comment


                                #30
                                This is unfortunately a limitation at this point in time, however it's on our list to look into, have you perhaps considered working with the 6J on Globex to test your position sizing, I find signals sometimes even clearer in those.
                                BertrandNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by bortz, 11-06-2023, 08:04 AM
                                47 responses
                                1,603 views
                                0 likes
                                Last Post aligator  
                                Started by jaybedreamin, Today, 05:56 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post jaybedreamin  
                                Started by DJ888, 04-16-2024, 06:09 PM
                                6 responses
                                18 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by Jon17, Today, 04:33 PM
                                0 responses
                                4 views
                                0 likes
                                Last Post Jon17
                                by Jon17
                                 
                                Started by Javierw.ok, Today, 04:12 PM
                                0 responses
                                12 views
                                0 likes
                                Last Post Javierw.ok  
                                Working...
                                X