Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Subject: Bracket Order Setup in NinjaScript - Handling Fast Market Conditions

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

    Subject: Bracket Order Setup in NinjaScript - Handling Fast Market Conditions

    Hello,

    I'm currently working on a NinjaScript strategy and I'm seeking advice on the best approach for setting up a bracket order to handle fast market conditions.

    Here's my current approach:
    1. In the OnBarUpdate method, when a valid long condition is met, I enter a long position

      Click image for larger version

Name:	image.png
Views:	252
Size:	114.7 KB
ID:	1306454
    2. If the long entry is filled, I set the stop loss and limit orders for the bracket in the OnExecutionUpdate

      Click image for larger version

Name:	image.png
Views:	289
Size:	190.8 KB
ID:	1306453
    The problem I'm facing is that in fast market conditions, the long entry may get filled, but the stop loss or limit orders fail to be placed because the stop loss price, which is referencing the Position.AveragePrice with an Offset, can be above the market. This results in an error like:

    Time Category Message 6/7/2024 8:30:01 AM Order Sim101, Stop price can't be changed above the market. affected Order: Sell 1 StopMarket @ 5366.25

    The behavior I want to avoid is having a naked long position with no stop order, which is what happening in this edge case.

    I would greatly appreciate any insights, suggestions, or alternative approaches to handle this scenario effectively. The goal is to ensure that the stop loss and target orders are always placed, even in fast market conditions, to prevent naked positions.

    Thank you in advance for your help!
    ​​

    #2
    Hello Tradewave,

    If the calculated price for the stop is equal to or above the bid (for a sell stop) or equal to or below the ask (for a buy) stop, you could submit a market order to immediately exit the trade instead of submitting a stop order with an invalid price.

    Below is a link to a forum post with suggested sample code.


    Also, you may find these examples that demonstrates OCO helpful.
    ProfitChaseStopTrailUnmanagedExample - https://support.ninjatrader.com/s/ar...ase-Stop-Trail
    UnmanagedOCOBracketExample​ - https://forum.ninjatrader.com/forum/...elp#post770579
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    68 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X