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 charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            51 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            142 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            160 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            96 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            275 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X