Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Placement with Stop and Take Profit by clicking (Bracket Order)

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

    Order Placement with Stop and Take Profit by clicking (Bracket Order)

    Hi,

    I am trying do develop some custom enhancement for my Ninjatrader. What I want to achieve is, I want to plan a bracketed order in advance, meaning that I want to place a Buy / Sell LMT for example, but that entry order gets a stop and take profit automatically attached after being filled. I know about ATM Strategies, with their fixed difference to the entry. The problem is, that I don't need a fixed difference. I also do not want to always use a custom ATM manually, because I find this tedious.

    That is why I want to create sth., where I can click for the entry, stop and take profit on my chart, for example 1st click is entry, 2nd click the stop and the 3rd is the TP. I already get the clicked prices correctly, but now I wonder what approach I can take for the order placement / submits. I want the stop and TP as OCO (of course), but they shall only get submitted after the entry order got filled. I used the TWS from IB for some time, there this was easily achieved with a bracket order and so called "Keys": 1.0 was the Entry, 1.1 and 1.2 the stop and TP, but they got only submitted after the filled entry and everything was submitted in advance and monitored on their servers. I would really appreciate sth. like this, since it is a nightmare for me if I would have to monitor the fill on my computer, because if I submit an order that way and my computer crashes, I would have an "unprotected" order in the market with no stop or TP getting submitted after its fill...

    I also thought about sth. like creating a custom ATM Strategy based on the clicks every time, but I am afraid generating a custom ATM stratety in a script is currently not possible?

    So my "real" questions:
    1) Do I have to monitor the entry to get filled by myself or is there a function I can use for that, preferrably server-sided?
    2) What is the best approach do model this regarding orders? I got a littble bit confused, since I can use Account.Orders or a "managed" or "unmanaged" approach. I already read the Help-Pages, but that did not really help with my problem here
    3) Is it possible to generate a custom ATM Strategy in a script
    4) Is it better to use an Add On, Indicator or Strategy here? I got a little bit confused, since they seem to differ on what resources the script gains access to...

    I hope my problem got clear, otherwise please ask!

    Best regards





    #2
    Hello mbwh1989,

    Thank you for your note.

    1) Do I have to monitor the entry to get filled by myself or is there a function I can use for that, preferrably server-sided?

    If you program a Buy Limit or Sell Limit order, then these orders will be submitted server-side and will be working at the brokerage/exchange for the order fills. You would not have to monitor the entry yourself.

    2) What is the best approach do model this regarding orders? I got a littble bit confused, since I can use Account.Orders or a "managed" or "unmanaged" approach. I already read the Help-Pages, but that did not really help with my problem here
    4) Is it better to use an Add On, Indicator or Strategy here? I got a little bit confused, since they seem to differ on what resources the script gains access to...

    These questions are both very similar. If you are looking to have the orders based on mouse clicks, an Add On would probably be the best fit for what you are trying to achieve. This would use the Account class and the orders would be submitted in an unmanaged approach; the internal order handling rules of the managed approach would not apply.

    The Account class uses CreateOrder() to place orders:


    An OCO ID could be used to tie together your stops and targets as OCO orders, or you could use StartAtmStrategy() to use an ATM strategy with an entry order:


    3) Is it possible to generate a custom ATM Strategy in a script

    StartAtmStrategy() uses the name of an existing ATM strategy template to function. There is no supported/documented way to save an ATM strategy template via NinjaScript. Templates must be created through the UI available in the Order Entry windows. You could instead create your own logic that behaves in a similar way to ATM strategies, where you have an entry order and once that order is filled in OnOrderUpdate() you submit protective stop and target orders. If a stop or target order is filled or canceled, the other stop/target paired via OCO would also cancel. We have more information about using ATM strategies in NinjaScript here:


    There is a reference sample for a NinjaScript Strategy using the Managed approach that uses OnOrderUpdate() and OnExecutionUpdate() to submit protective orders rather than using an ATM strategy here:


    For more information about add on development as well as an example of working with mouse clicks in an Add On script that uses the Account class to submit orders, please review the Add On development information here and the Add On Framework example that may be downloaded from this same page:



    I understand this is a lot of information. Please feel free to reach out with any additional questions or concerns.

    Comment


      #3
      First of all, thank you very much for your response, I will work my way through that material! Regarding my first question I would like to add: When I submit a Buy or Sell Limit order, is there a way to directly submit a Stop / TP along with it to the servers? Or do I have to monitor the fill of my Buy / Sell Limit with my AddOn, so that after the Buy / Sell Limit got filled, my Stop / TP gets submitted to the servers by my AddOn? I would really appreaciate to submit the stop / TP directly with the entry order, but the stop / TP should only get "activated" after the entry order got filled.

      Comment


        #4
        Hello mbwh189,

        Thank you for your reply.

        Once an order is submitted to the servers, once the broker accepts the order it is in an "activated" working state. We have the order state definitions in our help guide here:


        If you are wanting to submit a stop loss or profit target order along with the entry order, then it is possible to have all orders working and depending on the movement of the market you could potentially have your stop or target filled before the actual entry order is filled. NinjaTrader ATM strategies and the reference sample provided wait for the entry order to be filled before submitting the stop and target orders to the servers. You could certainly program your strategy/add-on to submit all three at the same time, although the results may vary.

        By having logic in place to determine when the stop loss and profit target orders should be submitted, this is like having the orders prepped to be sent to the servers the instant the entry is filled. In that moment once the entry is filled, the orders would be officially submitted and, if accepted, they would be activated (working state) on the servers.

        I hope this is useful information. Please let us know if we may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X