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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    120 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X