Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnPositionUpdate problem

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

    OnPositionUpdate problem

    I have problem with Onpositionupdate.

    When strategy order profittarget get filled
    Inside OnpositionUpdate Close[0] value gives me one bar ealier value and not last Close value.

    protected override void OnPositionUpdate(IPosition position)
    {
    if (position.MarketPosition == MarketPosition.Flat)
    {

    SendMail("[email protected]", "[email protected]", "Trade Alert: YM Close Long", "Close YM Long Position: "+Close[0]);

    }


    }

    #2
    Hello,

    NinjaTrader is multi-threaded and as such things are not guaranteed to be in any sequence. OnPositionUpdate will return values at the moment it processes.
    DenNinjaTrader Customer Service

    Comment


      #3
      Hello

      Originally posted by NinjaTrader_Ben View Post
      Hello,

      NinjaTrader is multi-threaded and as such things are not guaranteed to be in any sequence. OnPositionUpdate will return values at the moment it processes.
      It's not look like, because it will give value of ealier bars close.

      If My proft target is hit and prices is going up, how value can be lower and same as Close[1].

      Please test your self.

      Comment


        #4
        If in you are running your strategy with "Calculate on bar close" set to true then:

        - Any time you reference Close[0] it will return to you the close price of the last completed bar

        If in you are running your strategy with "Calculate on bar close" set to false then:

        - Close[0] will reference the most recent close price for the current bar which is not yet closed
        RayNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Ray View Post
          If in you are running your strategy with "Calculate on bar close" set to true then:

          - Any time you reference Close[0] it will return to you the close price of the last completed bar

          If in you are running your strategy with "Calculate on bar close" set to false then:

          - Close[0] will reference the most recent close price for the current bar which is not yet closed

          I want use Calculate on bar close.
          Ok how I can get Current price (Bid,Ask,Last Price), because I need it. When Ninja Profit Target or Stop Loss hits. It Should Be some where in Ninja.

          Comment


            #6
            Hello,

            The OnBarUpdate() method gets called only when the bar is updated. Since you want CalculateOnBarClose = true, then the newest prices will only be available after the bar closes. The prices then will not be updated until the next bar updates.

            You will not have access to the "latest" prices if CalculateOnBarClose = true.

            This link may help:
            DenNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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