Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss and SetProfitTarget example

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

    SetStopLoss and SetProfitTarget example

    Hello,

    Is there sample code available that elegantly handles partial fills when an order is created, and properly assigns the stop and profit targets? I am continually running into issues, e.g: stop or profit triggers on a long position, but additional orders are sent to go short; or the stop and target don't get placed at all. These issues only happen on a live feed.

    Thanks!

    #2
    Hello shadowfax,

    Thanks for your post.

    I would expect the Set methods to properly protect a position even in the event of a partial fill.

    Do you see the issue with the attached script? This script will enter a long position after enabling the strategy for the quantity specified. If you see an issue here, what instrument are you trading on and who is your broker? Is the trade submitted to the live account or with the Sim101 account? Please also ensure you are updated to the latest version of the platform before testing further.

    Update - https://ninjatrader.com/PlatformDirect

    If you do not see an issue testing this script, could you modify the example so it models what you are doing with the Set methods? The modification should not be your personal trading signal logic but should demonstrate how the issue can be encountered. We could then provide additional insight or investigate further if an issue is spotted on the platform's end.

    Note that when using Set methods outside of State.Configure/State.DataLoaded, these methods should be used when the strategy is flat and before the entry is submitted. (Set methods prep NinjaTrader to submit targets/stops when the strategy sees that the entry order has filled.) An example demonstrating best practices for using Set methods dynamically can be found below.

    SamplePriceModification - https://ninjatrader.com/support/help...of_stop_lo.htm

    Outside of set methods, our SampleOnOrderUpdate strategy has some logic for protecting partially filled entries.



    I look forward to hearing back.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    46 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
    66 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