Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategyCreate going into endless loop

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

    AtmStrategyCreate going into endless loop

    So I created a new ATM strategy within a strategy, but upon trigger, it goes into an endless loop creating unlimited ATM orders.

    Code:
    // Condition set 1
                if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1))
                {
    			AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
                TimeInForce.Day, GetAtmStrategyUniqueId(), "CL-Ichi",
                GetAtmStrategyUniqueId());
                }
    
                // Condition set 2
                if (CrossBelow(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1))
                {
                AtmStrategyCreate(OrderAction.Sell, OrderType.Market, 0, 0,
                TimeInForce.Day, GetAtmStrategyUniqueId(), "CL-Ichi",
                GetAtmStrategyUniqueId());
                }
            }
    What am I doing wrong? I only want it to create one instance of the order per trip

    #2
    Hello rdavido,

    Thank you for your post.

    ATM Strategy methods are not affected by settings such as EntriesPerDirection. The SampleAtmStrategy that is available in your installation of NinjaTrader under Tools > Edit NinjaScript > Strategy > SampleAtmStrategy, demonstrates how to limit entries through using set string variables to hold atmStrategyIds and orderIds to check if an order has been submitted already.

    If you have any questions please let me know.

    Comment


      #3
      I have the exact code from the Sample ATM strategy and it still creates looping orders in MarketReplay.

      Comment


        #4
        Hello rdavido,

        Thank you for your response.

        Can you provide your full strategy code or it's file?

        Comment


          #5
          I'm running this in market replay.
          Attached Files

          Comment


            #6
            Hello rdavido,

            Thank you for your response.

            Your code shows that you check that the Length of the two Ids are 0 then submit an EnterLong() and check if your position is Long before you submit an ATM Strategy.
            However, on the next pass the Length is not 0 and the position update would not occur during OnBarUpdate() processing.

            Try checking the cross above and below conditions outside of checking the Length of the Ids and then test the strategy again.

            For example:
            Code:
                        // Condition set 1
                        if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1))
            			EnterLong(DefaultQuantity, "Long");
                        if (orderId.Length == 0 && atmStrategyId.Length == 0)
                        {

            Comment


              #7
              Ok, now my orders are going through again, but none of the conditions are met to initiate the ATM order alongside my EnterLong. Even adjusting the code doesn't help. We're close. Before it was looping ATM strategies, now it's not initializing it.

              Code:
                    if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1))
              			if (orderId.Length == 0 && atmStrategyId.Length == 0)
              			EnterLong(DefaultQuantity, "Long");
              			if (Position.MarketPosition == MarketPosition.Long)
              			AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "CL-Ichi",	atmStrategyId);{

              Comment


                #8
                Hi rdavido,

                The bracket syntax is getting a bit confusing here.

                The following is one condition and one action that is independent of the next condition and action:

                if (CrossAbove(TSIchimoku(9, 26, 52).TenkanSen, TSIchimoku(9, 26, 52).KijunSen, 1))
                if (orderId.Length == 0 && atmStrategyId.Length == 0)
                EnterLong(DefaultQuantity, "Long");

                Then the Atm Strategy is created if the position is long:
                if (Position.MarketPosition == MarketPosition.Long)
                AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "CL-Ichi", atmStrategyId);{

                There is a weird opening curly brace that follows this {
                This curly brace and the matching closing curly brace are likely useless as they are not associated with the condition before it.


                The likely issue is if (Position.MarketPosition == MarketPosition.Long).

                If you are using Atm Strategies in your code, these orders will not affect the NinjaScript Strategy's position. The script will not see these orders because the script is no longer placing these orders.

                By calling AtmStrategyCreate, you have asked NinjaTrader outside of your script to place an order and automatically handle this with the Atm Strategy logic that is part of the core application.

                At this point the orders are hidden from your script and you will need to check on the status as well as manage orders through Atm Strategy methods.

                The method to check the position is GetAtmStrategyMarketPosition().

                Below is a link to the help guide on GetAtmStrategyMarketPosition().
                http://www.ninjatrader.com/support/h...etposition.htm
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Mestor, 03-10-2023, 01:50 AM
                16 responses
                388 views
                0 likes
                Last Post z.franck  
                Started by rtwave, 04-12-2024, 09:30 AM
                4 responses
                31 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Started by yertle, Yesterday, 08:38 AM
                7 responses
                29 views
                0 likes
                Last Post yertle
                by yertle
                 
                Started by bmartz, 03-12-2024, 06:12 AM
                2 responses
                22 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by funk10101, Today, 12:02 AM
                0 responses
                7 views
                0 likes
                Last Post funk10101  
                Working...
                X