Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleOnOrderUpdate

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

    SampleOnOrderUpdate

    In the example of the SampleOnOrderUpdate, it gives an example of how to monitor a long position.

    // Update our exit order quantities once orderstate turns to filled and we have seen execution quantities match order quantities
    else if (execution.Order.OrderState == OrderState.Filled && sumFilled == execution.Order.Filled)
    {
    // Stop-Loss order for OrderState.Filled
    stopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - 4 * TickSize, "MyStop", "MyEntry");
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + 8 * TickSize, "MyTarget", "MyEntry");
    }
    // Update our exit order quantities once orderstate turns to filled and we have seen execution quantities match order quantities
    else if (execution.Order.OrderState == OrderState.Filled && sumFilled == execution.Order.Filled)
    {
    // Stop-Loss order for OrderState.Filled
    stopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - 4 * TickSize, "MyStop", "MyEntry");
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + 8 * TickSize, "MyTarget", "MyEntry");
    }

    How would I code those lines of code to manage a short position?

    Also, and how would I code the example if I have multiple entry signals?

    Thanks,

    #2
    Hello AdeptistJune,

    In the code you have extracted you can see the order names which would be how you find orders in OnOrderUpdate or OnExecutionUpdate. If you have multiple orders you just look for the order name which you want.

    That sample only has a few variables, if you wanted to expand it to support many orders you could create more variables and then make many conditions inside OnorderUpdate to find specific order names.
    You can see a sample of using the name here: https://ninjatrader.com/support/help...=onorderupdate

    Code:
    if (order.Name == "MyLongEntry")
        myLongEntryVariable  = order;

    Please let me know if I may be of additional assistance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X