Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position.AvgPrice querie

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

    Position.AvgPrice querie

    Im starting to feel like im going to have a lot of questions, any help appreciated. Have the following procedure called from OnBarUpdate()


    private void GoLong()
    {

    EnterLong("target1");

    Print(Time[0].ToString()+ " Position.AvgPrice:" + Position.AvgPrice.ToString());

    If i enter as above in my EOD strategy Position.AvgPrice is returning 0

    I need to work out if the entry price - yesterdays low is greater than 100 and set my initial stop accordingly

    Cheers,
    Jlo

    #2
    Hi Jlo,

    This will return 0 when not in a position. When you access it at the same time you submit the order, it won't have a chance to be filled yet. Better would be to move it to OnBarUpdate() and check it when you are not flat.

    if (Position.MarketPosition != MarketPosition.Flat)
    Print(Time[0].ToString()+ " Position.AvgPrice:" + Position.AvgPrice.ToString());
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      does that mean that on an end of day strategy i could not set the stop until the following day ie. onbarupdate re-occurs?

      thanks for the reply

      Comment


        #4
        It's possible but requires advanced handling. If you need to base any calculations on position average price but cannot wait until the next bar update, then you can work in our advanced framework with IOrders. OnExecution() handler is used for monitoring for order fills.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          ok thanks, another question if you have the time

          How do i tell what the current stop value is for a position ie. I set

          SetStopLoss("L1", CalculationMode.Price,tmpStop,false);

          can I look back at this value later on or do i need to store it via a variable

          Regards,
          JLo

          Comment


            #6
            Yes, you can access the price of these orders. The technique is shown in this reference sample:
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            670 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X