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 lightsun47, Today, 03:51 PM
      0 responses
      5 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      9 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      45 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      9 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X