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 pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    11 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    16 views
    0 likes
    Last Post AaronKoRn  
    Working...
    X