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

ATM Reverse at stop enabled. NT8

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

    ATM Reverse at stop enabled. NT8

    Hello mates,

    I use an AutoStrategy that close everything at time end. The strategy use the ATM for manage the orders. The issue comes when I enable the feature Reverse at stop that is into the ATM strategy. (GUIDE FOR AUTOREVERSE https://ninjatrader.com/support/help...to_reverse.htm

    When I enable it it creates a Sell Stop or Buy Stop than reverse to buy or sell when the Stop Loss is reached by the price.

    The issue is:

    One order/position still OPEN sometimes without Stop Loss and Take profrit after use the function :Account.Cancel(orders);

    its not canceled!!

    so is dangerous!!

    Below the code that I try to use but it doesnt close everything how expected. How can I solve the issue easily? I want to close all the remaining orders, positions (everything) but the strategy should stay enabled.

    Thanks for your help!


    Code:
    if (ToTime(Time[0]) >= ToTime( 10, 30, 00)) // The condition
    {
      var orders = Account.Orders.Where( x => x.Instrument == Instrument && !Order.IsTerminalState(x.OrderState));
                   if(orders.Count()!= 0)
                   {
                   Print( Name +", "+ Instrument.FullName +", "+ BarsArray[0].BarsPeriod +": active orders detected & canceled: " + orders.Count().ToString());
    
    [B]Account.Cancel(orders); [/B]// Cancel Everything
    
    
     }
    Last edited by bcomas; 08-29-2020, 07:08 AM.

    #2
    Hello bcomas,

    Thanks for your post.

    As you have already written into us directly on this same subject we will continue working with you through e-mail.
    I am just posting so the community is aware that we have responded to this topic.

    The current status is: This case has been raised to our QA team and as I have advised in e-mail, when there is an update I will contact you.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul again .

      The intention is to have it public . May be somebody in the community have the solution already.

      My best regards!

      Comment


        #4
        NT support response :

        We had to deliberately cancel the reversal order because the AtmStrategyId changes for the new ATM strategy associated with the reversal order.

        The NinjaScript strategy generates the AtmStrategyId it tracks when the NinjaScript strategy creates the entry for the first AtmStrategy. Subsequent ATM strategies that are spawned from reversals are not created from the NinjaScript strategy, and the NinjaScript strategy does not have knowledge of those new ATM strategies.

        If the ATM strategy reverses, we have a new ATM strategy that the NinjaScript strategy is not tracking. The ATM strategy that the strategy was tracking would be flat, and then the strategy would set it's atmStrategyId property to string.Empty. FlattenPosition then would not be called, and then AtmStrategyClose and Account.Cancel are not going to be called.

        Given what you are trying to accomplish with reversals and managing that position with code, I would suggest moving away from using Atm Strategies, and I would instead suggest to move forward programming everything within the NinjaScript strategy using the Managed Approach.

        With the Managed Approach, reversals can be made by calling EnterLong/EnterShort in the opposite direction. You could then consider using logic that checks if the current market price reaches a certain level (which would be your stop loss) and then you can call EnterLong/EnterShort to reverse the position.

        Managed Approach — https://ninjatrader.com/support/help...d_approach.htm

        End....


        Not the 100% effective but the best way to Flatten using the NinjaTrader ATM Reverse at stop feature together with AutoStrategies :
        It can be combined with the function : Account.Flatten(new[] { Instrument }); to make sure everything is closed.

        Code:
        // InPosition
        private bool InPosition { get { return atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat; } }
        
        // [B]Flatten function[/B]
        
        private void FlattenPosition()
        {
        if (InPosition)
        {
        foreach (Order order in Account.Orders) //First foreach loop, to get working orders
        {
        if(order.OrderState == OrderState.Working || order.OrderState == OrderState.Accepted) //This will print all working orders on the account
        {
        
        if (order.Name == "Entry") //Checks if the order name is Stop1, and if so, assigns it to an order object.
        {
        
        Account.Cancel(new[] { order }); /// Cancel the Buy Stop / Sell Stop (AutoReverse)
        
        }
        }
        }
        
        Print("Closing ATM for : " + atmStrategyId.ToString());
        
        AtmStrategyClose(atmStrategyId);
        
        atmStrategyId = string.Empty;;
        
        }
        
        }
        Last edited by bcomas; 09-04-2020, 07:15 AM.

        Comment


          #5
          Hey guys

          I have to chime in here:

          If the ATM strategy reverses, we have a new ATM strategy that the NinjaScript strategy is not tracking
          But this is a huge flaw. NT8 supports ATM's and therefore should allow coders to track the new ATM's ID. Moving away from the ATM altogether for the strat -- would defeat the purpose of the strat. It heavily relies on the use of ATM.

          So why wouldn't NT8 support this fully?

          Seems like a huge flaw that we're now being asked to workaround, vs. fixing it and supporting it fully.

          Comment


            #6
            Hello ZivGillat,

            Thanks for your post.

            Correct, the reverse at stop generates a new ATM that is outside of the Ninjascript strategy, therefore the Ninjascript strategy is not tracking it and cannot track it. The method AtmStrategyClose() closes the Atm strategy that the script created. It will not close entry orders for other Atm strategies. You cannot expect AtmStrategyClose to close the reversal entry order since it is for a new Atm strategy.".

            For a reverse at stop strategy, our recommendation is "Given what you are trying to accomplish with reversals and managing that position with code, I would suggest moving away from using Atm Strategies, and I would instead suggest to move forward programming everything within the NinjaScript strategy using the Managed Approach."
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              So would this affect a NinjaScript strategy that, for example, was in a long position that submitted a sell at market order to close long position, followed immediately by a NinjaScript short at market strategy?

              Today, I was in a NinjaScript long position that stopped out on a market order, but when the immediately following NinjaScript short position order was triggered, it was suddenly removed and I don't know why. Was it due to this issue? Because I can't figure out why it failed.

              Below is my log entry:




              9/18/2020 8:45 Position Instrument='ES 12-20' Average price=0 Quantity=0 Market position=Short Operation=Remove (WHY?)

              9/18/2020 8:45 Execution Execution='346151771405' Instrument='ES 12-20' Exchange=Globex Price=3347 Quantity=1 Market position=Short Operation=Operation_Add Order='1552289237' Time='9/18/2020 8:45 AM'




              Was my short position immediately removed because of this stop an reverse issue? Any insight would be helpful.

              Thanks!

              Comment


                #8
                Hello bootize,

                Thanks for your post.

                This thread is about a very specific topic of a Ninjascript strategy that is using an ATM strategy where the ATM strategy employed reverse at stop.

                If your strategy is not using an ATM with stop and reverse checked, then please either create a new forum topic or write into PlatformSupport[at]Ninjatrader[dot]Com with your questions.

                Thank-you.
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Spiderbird, Today, 12:15 PM
                2 responses
                10 views
                0 likes
                Last Post Spiderbird  
                Started by WHICKED, Today, 12:45 PM
                0 responses
                3 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by FrazMann, Today, 11:21 AM
                2 responses
                6 views
                0 likes
                Last Post NinjaTrader_ChristopherJ  
                Started by rjbtrade1, 11-30-2023, 04:38 PM
                2 responses
                80 views
                0 likes
                Last Post DavidHP
                by DavidHP
                 
                Started by lorem, Yesterday, 09:18 AM
                5 responses
                18 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X