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

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
    JimNinjaTrader Customer Service

    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