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

Manually modify strategy-generated orders

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

    Manually modify strategy-generated orders

    I currently have a strategy that submits a stop loss and a profit target when a stop limit entry order is filled, but I'm unable to move these orders around. What I would like to do is have the ability to move these orders up and down with a DOM or ChartTrader but whenever I do that now, they snap right back to their original price. Is there any way to accomplish what I'm looking for?

    Thanks - Brandon

    #2
    Hello Brandon,

    Thanks for your post.

    The SetStopLoss(), SetProfitTarget() and SetTrailStop() methods will all use internal rules that will update the stop or target to the assigned level after each bar closure.

    It is possible to use the Exit methods to serve as your profit target and stop loss with the isLiveUntilCancelled overload so the orders can then be adjusted manually.

    I've attached some sample code demonstrating how this is possible:
    Code:
    protected override void OnBarUpdate()
    {
    if(Historical)
    return;
    if(Position.MarketPosition == MarketPosition.Flat)
    EnterLong("MyEntry");
    }
    
    protected override void OnExecution(IExecution execution)
    {
    if(execution.Name == "MyEntry")
    ExitLongStop(0, true, 1, Position.AvgPrice - 10 * TickSize, "MyExit", "MyEntry");
    }
    Publicly available documentation on the methods used can be referenced below.

    OnExecution() - https://ninjatrader.com/support/help...nexecution.htm

    ExitLongStop() (Please see isLiveUntilCancelled overload) - https://ninjatrader.com/support/help...itlongstop.htm

    Also, for a more robust approach to using Exit methods for your protective orders as well as the OnOrderUpdate() and OnExecution() methods, I recommend reviewing the SampleOnOrderUpdate example.

    SampleOnOrderUpdate - https://ninjatrader.com/support/foru...ead.php?t=7499

    Please let us know if you have any additional questions.
    Last edited by NinjaTrader_ChelseaB; 10-14-2022, 08:02 AM.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by WeyldFalcon, 12-10-2020, 06:48 PM
    14 responses
    1,427 views
    0 likes
    Last Post Handclap0241  
    Started by Barry Milan, Today, 10:35 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by DJ888, Yesterday, 06:09 PM
    2 responses
    9 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    40 views
    0 likes
    Last Post jeronymite  
    Started by bill2023, Today, 08:51 AM
    2 responses
    16 views
    0 likes
    Last Post bill2023  
    Working...
    X