Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Setting Stop and Limit orders with Calculate.OnPriceChange vs Calculate.OnBarClose

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

    Setting Stop and Limit orders with Calculate.OnPriceChange vs Calculate.OnBarClose

    Hello,
    I have a strategy that, when entering a position, should also place stop and limit orders. The stop and limit orders are being placed, but not until the current bar finishes and the next one starts.

    I have `Calculate = Calculate.OnPriceChange;` in my `OnStateChange()` method, so I expect that the stop and limit orders should be placed as soon as the price changes (in the current bar).
    (I also see "OnPriceChange" selected in the Strategy popup window if I view that.)

    I'm using "separate logic" to place the initial order (and set a flag), and then on subsequent `OnBarUpdate()` calls, I check to see if the flag is set, and if so, use `ExitLongStopMarket()`, `ExitShortStopMarket()`, `ExitLongLimit()` and `ExitShortLimit()` methods to set the closing orders.

    So, I'm confused as to why the stop/limit orders aren't being set on the very next bar update after the order is placed.
    Any hints to point me in the right direction?
    Thanks!

    #2
    Hello GregX999,

    If you would like the orders submitted immediately when the entry fills, submit these from OnExecutionUpdate().

    Below is a link to an example (ProfitChaseStopTrailExitOrdersExample).
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ah! That did the trick! Thanks!

      (I really wish Playback mode worked the same as Live/Simulation mode. It's so annoying to get everything working perfectly in Playback and then having bugs/errors when trying to switch to Simulation. I had others besides this one, but was able to find the answers. This was the only one I needed to ask about here.)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jpeep, 08-16-2020, 08:31 AM
      17 responses
      502 views
      0 likes
      Last Post notenufftime  
      Started by ETFVoyageur, 05-07-2024, 07:05 PM
      15 responses
      124 views
      0 likes
      Last Post ETFVoyageur  
      Started by esmall, Today, 07:14 PM
      0 responses
      9 views
      0 likes
      Last Post esmall
      by esmall
       
      Started by Option Whisperer, 05-09-2024, 07:58 PM
      6 responses
      26 views
      0 likes
      Last Post Option Whisperer  
      Started by rayyyu12, Today, 05:38 PM
      0 responses
      13 views
      0 likes
      Last Post rayyyu12  
      Working...
      X