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

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.


    Paul H.NinjaTrader Customer Service

    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,
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by pechtri, 06-22-2023, 02:31 AM
        9 responses
        122 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by frankthearm, 04-18-2024, 09:08 AM
        16 responses
        66 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by habeebft, Today, 01:18 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by benmarkal, Today, 12:52 PM
        2 responses
        14 views
        0 likes
        Last Post benmarkal  
        Started by f.saeidi, Today, 01:38 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X