Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CreateOrder with OCO example?

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

    CreateOrder with OCO example?

    Hello,

    I am reading about CreateOrder here:

    https://ninjatrader.com/support/helpGuides/nt8/?createorder.htm

    In the parameters section is states:
    oco A string representing the OCO ID used to link OCO orders together
    May you please provide a simple example of using an OCO ID as stated here to enter an order with StopLoss and ProfitTargets with the CreateOrder method?

    Thanks!
    Last edited by focus333; 02-05-2021, 01:04 PM.

    #2
    Hello focus333,

    Thanks for your post.

    The best example would be the sample strategy in your platform called Sample ATM strategy. In there you will find this code:

    if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
    {
    isAtmStrategyCreated = false; // reset atm strategy created check to false
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
    //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
    if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
    isAtmStrategyCreated = true;
    });
    }


    This will create the entry order and the Stop/Profit are provided by the ATM template (in this example called AtmStrategyTemplate.


    Comment


      #3
      Thank you!

      "This will create the entry order and the Stop/Profit are provided by the ATM template (in this example called AtmStrategyTemplate."

      Can the AtmStrategyTemplate's values be set on the fly? If so, how?

      In other words, can I use this approach but have the quantity, stopLoss value and profit value set programmatically right before entering the order or are the values always hard-coded in the template? With my situation, I need these values set differently for every call. Thanks!

      Click image for larger version  Name:	atm.PNG Views:	0 Size:	26.8 KB ID:	1140276

      Comment


        #4
        Hello focus333,

        Thanks for your reply.

        No, they are set according to the template.

        Of course, you can create as many ATM templates as you wish and call the one your need,

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        94 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        139 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        124 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        74 views
        0 likes
        Last Post PaulMohn  
        Working...
        X