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 SalmaTrader, 07-07-2026, 10:26 PM
            0 responses
            45 views
            0 likes
            Last Post SalmaTrader  
            Started by CarlTrading, 07-05-2026, 01:16 PM
            0 responses
            22 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 06-17-2026, 10:32 AM
            0 responses
            14 views
            0 likes
            Last Post CaptainJack  
            Started by kinfxhk, 06-17-2026, 04:15 AM
            0 responses
            20 views
            0 likes
            Last Post kinfxhk
            by kinfxhk
             
            Started by kinfxhk, 06-17-2026, 04:06 AM
            0 responses
            22 views
            0 likes
            Last Post kinfxhk
            by kinfxhk
             
            Working...
            X