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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        656 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        371 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X