Announcement

Collapse
No announcement yet.

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 Roman Hrabovskyi, Today, 07:51 AM
          0 responses
          6 views
          0 likes
          Last Post Roman Hrabovskyi  
          Started by Scotty33, Today, 05:45 AM
          1 response
          13 views
          0 likes
          Last Post s.kinra
          by s.kinra
           
          Started by aaajv, Today, 06:45 AM
          0 responses
          4 views
          0 likes
          Last Post aaajv
          by aaajv
           
          Started by MarkTee, Today, 02:53 AM
          0 responses
          6 views
          0 likes
          Last Post MarkTee
          by MarkTee
           
          Started by TheCatTrader, Yesterday, 04:52 PM
          2 responses
          15 views
          0 likes
          Last Post TheCatTrader  
          Working...
          X