Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnPositionUpdate() vs. OnBarUpdate()

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

    OnPositionUpdate() vs. OnBarUpdate()

    Hi,

    I am confused between these 2 methods. I have code that generates an unmanaged bracket order in opposite directions of the current price. They are NOT tied together via OCO. However when one order is filled I would like to trigger a trailing stop loss that "chases" my live order to capture profits.

    I've placed my initial unmanaged bracket orders in OnMarketData(). I also place stop loss orders in OnExecutionUpdate() to generate when one of my initial bracket orders are filled.

    My question is this. I am placing a ChangeOrder() function for my stop loss order in OnBarUpdate() so as to adjust the order every time price moves into profit. Should I be using OnPositionUpdate instead or is OnBarUpdate better???

    #2
    Hello jm_test19,

    OnBarUpdate() updates when the bar updates. For Calculate OnBarClose this updates when the bar closes, for Calculate.OnPriceChange this updates when the price changes, for Calculate.OnEachTick this updates when a tick has been received.

    OnPositionUpdate() updates when the position changes. If the position is flat and an entry order fills, this will update with the Long or Short position. If the position quantity changes this will also update OnPositionUpdate().

    For trailing action this would be when the price changes and should be in OnBarUpdate().

    Below is a link to an example of custom stop price modification.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Can you reference Position.MarketPosition in the onBarUpdate method. For instance can you have the following:

      protected override void OnBarUpdate()
      {

      if (Position.MarketPosition == MarketPosition.Flat)
      {
      Logic
      }

      if (Position.MarketPosition == MarketPosition.Long)
      {
      Logic
      }


      if (Position.MarketPosition == MarketPosition.Short)
      {
      Logic
      }

      }

      Can it read the market position even though you're NOT using the onPositionUpdate method. onPositionUpdate is the method that utilizes these parameters​ of "MarketPosition". From what I understand onBarUpdate doesn't use any parameters.

      Thank You,

      Comment


        #4
        Hello jm_test19,

        Yes, you can reference Position.MaeketPosition from OnBarUpdate()
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you. Also is there anyway to submit unmanaged bracket orders that are Limit orders? I'd like to place a bracket limit order that would "reserve" 2 spots on the depth of market chart that way I can be somewhat protected from slippage. The problem is that limit orders are executed at a specific price or better. So if I place a limit order to buy at a higher price than the current price the order would execute right away. Is there any alternative to Limit orders that would reserve my place on the DOM?

          Comment


            #6
            Hello jm_test19,

            Yes, the unmanaged approach can be used to submit two orders with OCO.

            Below is a link to an example.


            As well as a link to the documentation.
            Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

            Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.



            A buy limit order fills at the specified limit price or better if the ask price is equal to or below the limit price.
            A sell limit order fills at the specified limit price or better if the bid price is equal to or above the limit price.
            A buy stop order fills at market if the ask price touches the stop price and must be submitted with the stop price above the ask.
            A sell stop order fills at market if the bid price touches the stop price and must be submitted with the stop price below the bid.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            557 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 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
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X