Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on ATM Strategy called by Ninja Strategy

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

    Error on ATM Strategy called by Ninja Strategy

    Hi,
    I have implemented a Strategy that use ATM strategy to manage the order.
    I have used the code of the sample provided with the platform.

    It works fine except when market is fast and the OCO order are rejected.


    this is an error message of that situation:

    2021-12-10 14:30:03:821|1|32|Order='b32dcc5c81de44309ab98a6e6 ba539ec/Simstrategy3' Name='Stop1' New state='Rejected' Instrument='MNQ 12-21' Action='Buy to cover' Limit price=0 Stop price=16163.75 Quantity=1 Type='Stop Market' Time in force=GTC Oco='9530e85147ef4be7897fea8ed74221e2' Filled=0 Fill price=0 Error='Order rejected' Native error='Buy stop or buy stop limit orders can't be placed below the market.'
    2021-12-10 14:30:03:823|0|32|Simstrategy3, Buy stop or buy stop limit orders can't be placed below the market. affected Order: BuyToCover 1 StopMarket @ 16163,75
    2021-12-10 14:30:03:830|1|32|Order='ded9aa708144498ea4ebaeb23 a410072/Simstrategy3' Name='Target1' New state='Rejected' Instrument='MNQ 12-21' Action='Buy to cover' Limit price=16137.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='9530e85147ef4be7897fea8ed74221e2' Filled=0 Fill price=0 Error='Unable to submit order' Native error='Order 'ded9aa708144498ea4ebaeb23a410072' can't be submitted: The OCO ID ‘9530e85147ef4be7897fea8ed74221e2’ cannot be reused. Please use a new OCO ID.'
    2021-12-10 14:30:03:830|0|32|Simstrategy3, Order 'ded9aa708144498ea4ebaeb23a410072' can't be submitted: The OCO ID ‘9530e85147ef4be7897fea8ed74221e2’ cannot be reused. Please use a new OCO ID. affected Order: BuyToCover 1 Limit @ 16137,25


    I would like to deal this with command : "AtmStrategyClose(string atmStrategyId)"
    but at this point I don't have idea how to trigger the error and then apply the command above.

    Could you send me an example of coding?...
    I'm suggesting you to also add it to the sample code

    Thanks
    Roberto

    #2
    Hello truesailor1,

    Thanks for your post.

    If Atm Strategy methods are used to place orders and the stop loss order is rejected then GetAtmStrategyStopTargetOrderStatus() cannot be used after trade is closed to check if the State of the order is Rejected. You would see a message in the Output window similar to the following.

    'GetAtmStrategyStopTargetOrderStatus' method error: ATM strategy ID '1cfbd0c8cc8147f29dee3b2c3de024dc' does not exist or is already in a terminated state

    This is cause atmStrategyId was not reset because the atm strategy never went flat, but the atm strategy itself no longer exists. We are currently tracking an internal feature request ticket related to this that 'Allows use of GetAtmStrategyStopTargetOrderStatus() after trade is closed'. I have added your vote to this feature request.

    The internal tracking number for your feature request is SFT-4832. Please reference this internal tracking number when contacting Platform Support if you ever have questions regarding this feature request.

    When a feature request is implemented, you'll find a description of the new feature in the release notes:In the meantime, you could consider the following workaround. You could loop through the Account.Orders collection to find the rejected order, then you could submit a market order with Account.CreateOrder/Account.Submit to close the position.

    See the help guide documentation below for more information and example code.
    Account: https://ninjatrader.com/support/help...ount_class.htm
    Account.Orders: https://ninjatrader.com/support/help...rs_account.htm
    Account.CreateOrder: https://ninjatrader.com/support/help...reateorder.htm
    Account.Submit: https://ninjatrader.com/support/help...nt8/submit.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon ,
      thanks for replay.

      first question: the rejected order is an OCO order ..could I check in order collection to find the open position directly and close it with a market order? without looking fo the rwjected order?

      second question: I noticed that the ATM strategy, after this type of error continue to submit orders and this is not good, so I have to reset ATM strategy too and the following code:

      "// If the strategy has terminated reset the strategy id
      else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
      atmStrategyId = string.Empty;
      "
      doesn't work.

      My fear is that while I'm closing a position with OCO reject order other position get alive (do to ATM strategy anmaneged) without any control.

      bye
      Roberto

      Comment


        #4
        Hello truesailor1,

        Thanks for your note.

        You would not be able to get the order without looping through the Account.Orders collection. To find the open position you would need to loop through the Account.Orders collection to find the rejected order. You could then submit a market order using Account.CreateOrder/Account.Submit to close the position.

        As for your second question, the best solution would be to determine what is causing the order to be rejected and modify your code so that the order is not being rejected. If the order is being rejected because of a fast market, you could consider using a stop loss and profit target with prices that are farther away from the entry order.

        Note in a strategy you would only have these ATM Strategy methods to work with and they are not synced, meaning the ATM Strategy is a separate strategy that is running on its own. So in some cases and depending on when it updates in the strategy like on bar close, the NinjaScript strategy may not catch the events of the ATM Strategy. This is why ATM Strategies would not be a great candidate if you are attempting to do any advanced NinjaScripting.

        Atm Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hello BrandonH,

          Originally posted by NinjaTrader_BrandonH View Post
          Note in a strategy you would only have these ATM Strategy methods to work with and they are not synced, meaning the ATM Strategy is a separate strategy that is running on its own. So in some cases and depending on when it updates in the strategy like on bar close, the NinjaScript strategy may not catch the events of the ATM Strategy.
          1 Can you explain what it means to be out of sync?
          2 "So in some cases and depending on when it updates in the strategy like on bar close, the NinjaScript strategy may not catch the events of the ATM Strategy."
          Can you explain more? Why is it not received when bar close?

          Thank you

          Comment


            #6
            Hello jetheil2,

            Thanks for your note.

            The 'Sync' column in the Strategies tab of the Control Center shows if your strategy position and account position is in sync. Note that strategy positions are separate from actual account positions.

            If your strategy position and account position is matching, the Sync column will read True. If your strategy position and account position do not match, the Sync column will read False.

            See this help guide page for more information about Strategy vs Account Position: Strategy vs. Account Position — https://ninjatrader.com/support/help..._account_p.htm

            Since the Atm strategy is a separate strategy from the NinjaScript strategy, the Atm strategy could update and process information intrabar instead of only at the close of each bar. If you are running a NinjaScript strategy with Calculate.OnBarClose, then the NinjaScript strategy would not read any Atm strategy events that occurred intrabar. The Atm Strategy Methods called in the NinjaScript strategy would only update and process information OnBarClose instead of intrabar unless you run the NinjaScript strategy with Calculate.OnEachTick or OnPriceChange.

            See this help guide for information about Calculate: https://ninjatrader.com/support/help.../calculate.htm

            Additional information could be found in this forum thread - https://ninjatrader.com/support/foru...ion#post811541

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by fwendolynlpxz, Today, 05:19 AM
            0 responses
            3 views
            0 likes
            Last Post fwendolynlpxz  
            Started by traderqz, Yesterday, 12:06 AM
            11 responses
            28 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by PaulMohn, Today, 03:49 AM
            0 responses
            8 views
            0 likes
            Last Post PaulMohn  
            Started by inanazsocial, Today, 01:15 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by rocketman7, Today, 02:12 AM
            0 responses
            11 views
            0 likes
            Last Post rocketman7  
            Working...
            X