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

unmanaged mode / order size problems in own script changeorder

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

    unmanaged mode / order size problems in own script changeorder

    Hi, I have my own script, so far so good. if i want to change the order size manually via charttrader, it only works downwards, upwards an additional new order is generated. in the script i query every change of the order in the OnOrderUpdate method. how can i change the existing order size instead of creating a new order?

    Attached Files
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello slidercom80,

    Thanks for your post.

    There is not enough detail provided to understand how your logic is not allowing orders to be changed in the upward direction.

    To achieve your goal, I would suggest checking to see which order has changed after your order object assignment and nulling (if order has been cancelled) code in OnOrderUpdate, and then to modify the other order that you have paired with that order.

    I have tested the following and I have not had trouble in my test script. I have attached it for your reference.

    Code:
    // Check if entry orders have been modified by user
    
    if ((shortEntry != null && longEntry != null) && (order == shortEntry || order == longEntry) &&
    (shortEntry.OrderState == OrderState.Accepted || shortEntry.OrderState == OrderState.Working) &&
    (longEntry.OrderState == OrderState.Accepted || longEntry.OrderState == OrderState.Working))
    {
        if (order.Quantity != shortEntry.Quantity)
          ChangeOrder(shortEntry, order.Quantity, shortEntry.LimitPrice, shortEntry.StopPrice); // longEntry was changed, update shortEntry
       else if (order.Quantity != longEntry.Quantity)
          ChangeOrder(longEntry, order.Quantity, longEntry.LimitPrice, longEntry.StopPrice); // shortEntry was changed, update longEntry
    }
    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi _Jim, thanks for the answer. i found the problem: since i don't use an oco order, the modified existing order couldn't be assigned correctly. i solved it by generating a separate oco id for the stoploss order and the takeprofit order. apparently nt needs an oco order for the assignment, the name of the order to be changed is probably not enough ;-)

      Code:
       if (State == State.Historical)
      {
      ocoSL = DateTime.Now.ToString() + CurrentBar + "LongExitsSL";
      ocoTP1 = DateTime.Now.ToString() + CurrentBar + "LongExitsTP1";
      }
      else
      {
      ocoSL = GetAtmStrategyUniqueId() + "LongExitsSL";
      ocoTP1 = GetAtmStrategyUniqueId() + "LongExitsTP1";
      }
      because i manage all orders by myself and independent from an oco link, i only need this oco id for changing the respective order by hand.
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by alifarahani, Today, 09:40 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by RookieTrader, Today, 09:37 AM
      4 responses
      17 views
      0 likes
      Last Post RookieTrader  
      Started by PaulMohn, Today, 12:36 PM
      0 responses
      5 views
      0 likes
      Last Post PaulMohn  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      40 views
      0 likes
      Last Post love2code2trade  
      Started by junkone, Today, 11:37 AM
      3 responses
      23 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X