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

Changing an existing order from an AddOn

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

    Changing an existing order from an AddOn

    Hello,

    I have used the AddOn Framework as a basis for my addon. I submit a bracket order with my stop loss and profit target like so:

    profitTarget = accountSelector.SelectedAccount.CreateOrder(e.Orde r.Instrument, thisOrderAction, OrderType.Limit, TimeInForce.Day, e.Order.QuantityChanged, localProfitTarget, localProfitTarget, oco, "LATA - Target", null);
    stopLoss = accountSelector.SelectedAccount.CreateOrder(e.Orde r.Instrument, thisOrderAction, OrderType.StopMarket, TimeInForce.Day, e.Order.QuantityChanged, localStopLoss, localStopLoss, oco, "LATA - Stop", null);
    accountSelector.SelectedAccount.Submit(new[] { profitTarget, stopLoss });

    Now I need to programmatically change the quantity and/or price of these orders but cannot figure out how it should be done. Is it even possible?

    Thank you,

    Libor
    Last edited by liborc; 06-05-2017, 02:51 PM.

    #2
    Hello liborc,

    This would be possible.

    You'll have to change the order objects price or size parameter, then pass the order object to the Change() call.

    A sample can be found at the following,


    Please let us know if this is unclear or you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      thank you very much for this info. I believe I discovered a bug in NT in this area.
      As I was looking for the solution, I tried changing the quantity of the order in the Orders collection. It is apparently supposed to be read only, but in fact it is read/write as it has a setter exposed. When I changed the quantity, it did not throw any error, only changed the order quantity in the order list in the Control Center. Naturally, the real order on the broker's server stayed unchanged.

      I hope this helps. Please let me know if you need more information or if I should log a bug report in a different fashion.

      Thank you again,

      Libor

      Comment


        #4
        Hello Libor,

        I'm trying to reproduce with no luck.

        I use the following code to submit an order to myInstrument which I have set to ES,

        Code:
        MyOrder = accountSelector.SelectedAccount.CreateOrder(myInstrument, buyOrSell, OrderType.Limit, TimeInForce.Day, 1,2450.00, 0, "", "EntryOrder", null);
        
        accountSelector.SelectedAccount.Submit(new[] {MyOrder});
        Then I use the following to amend the order, increasing it by a quantity of 2.

        Code:
        MyOrder.QuantityChanged= MyOrder.Quantity +2;
        
        accountSelector.SelectedAccount.Change(new[] { MyOrder });
        Is this similar to how your code looks? Would you be able to provide a sample or the logic you use to submit and amend the order?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi Alan,

          I have changed my code since I posted, but will try to see if I can reproduce and then update this thread with my findings.
          Overall, though, my code was along the lines of what you were using.

          Thank you,

          Libor



          Edit: I think actually I was doing something like:
          MyOrder = accountSelector.SelectedAccount.CreateOrder(myInst rument, buyOrSell, OrderType.Limit, TimeInForce.Day, 1,2450.00, 0, "", "EntryOrder", null);
          accountSelector.SelectedAccount.Submit(new[] {MyOrder});

          Subsequently modifying it like so (pseudocode):

          Order thisOrder = getReferenceToTheOriginal_MyOrder();
          thisOrder.Quantity = 33;



          I believe the Quantity property has a public setter.
          Last edited by liborc; 06-05-2017, 02:52 PM.

          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
          25 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X