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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            67 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            36 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            60 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            62 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            53 views
            0 likes
            Last Post CarlTrading  
            Working...
            X