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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        47 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        33 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        50 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Working...
        X