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

Logic behind Average Position Size

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

    Logic behind Average Position Size

    Hello there,


    Example:

    So I bought 5 contracts at 100$.

    Close is now at 150$ and broke through say a resistance at 120$. I now want to average my position price to 120$.

    How many contracts to add to my position to attain an average position price of 120$ ?


    #2
    Hello youdee101,

    Thanks for your question.

    This is less of a logical question but a mathematical one. The average position price is the average price for each contract entered. If you bought 5 contracts at 100, the average entry price is 100 because (100+100+100+100+100)/5 = 100.

    If you want to add contracts at the current market price to adjust average entry price to 120, you can use algebra.

    For example, you can set up the following equation and solve for x to get the number of contracts you need to buy to adjust the average entry price.

    (500 + 150x)/(5 + x) = 120.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you for the quick response!

      Comment


        #4
        Still more of a math than a logical problem.
        How would I refactor this equation, so I could use it as code to receive sharesToBuy as position size for the new order.
        First resistance of the pivot indicator is the desired new avg price in this example.

        x = sharesToBuy

        (Position.Quantity * Position.AveragePrice + Close[0]*x) / Position.Quantity + x ) = Pivots1.R1[0]

        I am trying to turn it to someting like: sharesToBuy = Variable1 * Variable2 / etc. + e.g


        if (CrossAbove(Close, Pivots1.R1, 1))
        {
        EnterLong(Convert.ToInt32(sharesToBuy), "");
        }

        Comment


          #5
          Hello youdee101,

          Helping out with your algebra is not exactly within our scope of services, but in order to be helpful, please consider the following:

          (500 + 150x)/(5 + x) = 120
          500 + 150x = 120 * (5 + x)
          500 + 150x = 600 + 120x
          500 + 150x - 120x = 600
          30x = 100
          x = 100/30
          x = 3.3

          You can use this model and replace different coefficients and values with your own variables. If you are looking for services to have the code written for you, you can consider hiring a NinjaScript Consultant. If that interests you, please let us know and we can have a colleague reach out with more information on those services.

          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          21 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X