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

Rejected Stop in ATM Strategy

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

    Rejected Stop in ATM Strategy

    I have written a strategy that is using an ATM Strategy Template to manage the trades. In fast moving markets, the stop orders are being rejected since the market price has already exceeded the stop level. When this happens, any methods referencing the AtmStrategyId give the error:

    AtmStrategyId 'XXXXX' does not exist or is already in a terminated state

    Is it possible to avoid this issue and have the strategy code handle the rejected order?

    #2
    Hello toptrader,

    Thanks for opening the thread.

    You can check the status of the order and attempt to change it if it is found and it exists.

    Here are two methods you can use:

    GetAtmStrategyStopTargetOrderStatus - https://ninjatrader.com/support/help...rgetorders.htm

    AtmStrategyChangeStopTarget - https://ninjatrader.com/support/help...stoptarget.htm

    If the order is marked as it does not exist, AtmStrategyChangeStopTarget will return false as it cannot find an associated order to change. In this case, I would advise to keep a looser ATM strategy template at the ready so you can enter with that ATM strategy if market conditions are too volatile for your primary ATM strategy.

    Please let me know if I can be of further help.
    JimNinjaTrader Customer Service

    Comment


      #3
      The problem is that this is leaving me in an unprotected position. The entry is filled, but the stop is rejected. Isn't it too late to use a "looser" template at that point? I would like the ATM Strategy to simply close the position if the stop gets rejected. Unfortunately, the AtmStrategyClose() method does not do this since the AtmStrategyId is either non existent or in a terminated state.

      Comment


        #4
        Hello toptrader,

        Thanks for the reply.

        The workaround would involve checking if the market conditions allow for you to enter with your primary ATM strategy. The check would have to be made before the ATM is entered so you can enter with a different ATM. In this case, you would have to program some of the ATM strategy logic by hand so you can detect if the strategy will be able to enter with it.

        I understand the usefulness of being able to correct the situation programmatically. As NinjaTrader 7 is in a freeze, we will not be able to submit any feature requests to have this behavior changed. We could submit a feature request for NinjaTrader 8, however.

        Could you provide me some accurate steps so I can reproduce this occurrence in NinjaTrader 8? I would be able to reproduce this easily with a day of Market Replay data and an entry signal that would cause an ATM strategy template to throw the error.

        I look forward to assisting you further.
        JimNinjaTrader Customer Service

        Comment


          #5
          If you create an ATM Strategy Template using a stop loss of 1 tick, the SampleAtmStrategy code should show the same error.

          Comment


            #6
            Hello toptrader,

            Thanks for your reply.

            I will need a case where I can reproduce this matter. When connected to the simulated data feed, I cannot receive the same errors when using AtmStrategyCreate() to initiate an ATM strategy with a 1 tick stop loss.

            I have attempted with using a custom bar type that increases volatility and I am still unable to enter an ATM strategy where the stop loss gets rejected.

            Could you provide me a scenario using the Market Replay data so I could check the behavior where AtmStrategyCreate() creates a stop loss above the market?

            Here is a video of my test: https://www.screencast.com/t/1cG2uvaAsVvk

            I look forward to assisting further.
            JimNinjaTrader Customer Service

            Comment


              #7
              This is extremely odd. Below is the log from when this issue happened the other day (it was running on a customers computer).

              Code:
              6/20/2017 6:04:29 AM|1|32|Order='79fdd00d633e402087596bcb740be647/Sim103' Name='Entry' New state=Filled Instrument='CL 08-17' Action=Buy Limit price=44.3 Stop price=0 Quantity=3 Type=Limit Filled=3 Fill price=44.3 Error=NoError Native error=''
              6/20/2017 6:04:29 AM|1|16|Execution='7a3e6c185f5b46cc991ffc145acf9e04' Instrument='CL 08-17' Account='Sim103' Exchange=Default Price=44.3 Quantity=1 Market position=Long Operation=Insert Order='79fdd00d633e402087596bcb740be647' Time='6/20/2017 6:04:29 AM'
              6/20/2017 6:04:29 AM|1|64|Instrument='CL 08-17' Account='Sim103' Avg price=44.3 Quantity=3 Market position=Long Operation=Update Currency=Unknown
              6/20/2017 6:04:29 AM|1|32|Order='e7599b00c0c1439e804b48a620f1832a/Sim103' Name='Stop1' New state=Rejected Instrument='CL 08-17' Action=Sell Limit price=0 Stop price=44.24 Quantity=3 Type=Stop Filled=0 Fill price=0 Error=OrderRejected Native error='Sell stop or sell stop limit orders can't be placed above the market.'
              6/20/2017 6:04:29 AM|0|32|Clive, Sell stop or sell stop limit orders can't be placed above the market. affected Order: Sell 3 Stop @ 44.24
              6/20/2017 6:04:29 AM|1|32|Order='a989ce0f6c5841f1ba9c75bf0bb3aafe/Sim103' Name='Target1' New state=PendingSubmit Instrument='CL 08-17' Action=Sell Limit price=44.42 Stop price=0 Quantity=3 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/20/2017 6:04:31 AM|3|128|GetAtmStrategyStopTargetStatus() method error: AtmStrategyId '1bed1313165b4358a576362b796fc62f' does not exist or is already in terminated state
              I've created and attached a sample strategy that will adjust the stop to a level that should be rejected every time. However, when I run the sample strategy it does not reject the stop order but rather fills it immediately (this is the behavior we want). I noticed on the customers computer, the stop loss order was a stop market order, where my computer is sending a stop limit order. I suspect this may be why I am not seeing the order rejected, however I have been unable to get the strategy to submit a stop market order so I can verify.

              I've changed the settings in Chart Trader, the DOM Windows, and the Basic Entry window (and set these as the default settings). However, the strategy continues to submit stop limit orders. It is using stop market orders when I manually place the trades through the DOM window, but not for the orders being generated by the strategy. How do I get the strategy to use stop market orders?

              Attached Files
              Last edited by toptrader; 06-23-2017, 07:33 AM.

              Comment


                #8
                Hi toptrader,

                I am not aware of a setting in NinjaTrader 7 to set the default for ATM's triggered by NinjaScript strategies. NinjaTrader 7 R32 included a change to have ATM strategies default to submit stop market orders for stop loss instead of limit orders. If you have the client's log and trace files, could you confirm that they are on a version later than R31?

                After testing your strategy with NinjaTrader 7 R35, on Market Replay for CL 08-17 on 6/20/2017, I could not get a rejection from AtmStrategyCreate(). I also observe that moving the stop loss with does not create an error with AtmStrategyChangeStopTarget when moving the stop loss above the market.

                Please let me know if updating the clients platform resolves the issue. If it does not, could you get the data series period the strategy was run against so we can reproduce with Market Replay?
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Gerik, Today, 09:40 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by RookieTrader, Today, 09:37 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by alifarahani, Today, 09:40 AM
                0 responses
                5 views
                0 likes
                Last Post alifarahani  
                Started by KennyK, 05-29-2017, 02:02 AM
                3 responses
                1,284 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by AttiM, 02-14-2024, 05:20 PM
                11 responses
                186 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X