Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATMStrategyCreate Issues

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

    ATMStrategyCreate Issues

    I want my script to initiate an ATM strategy when a buy/sell signal is generated. All my attempts so far have exceeded all too well. When the entry signals I wind up with a new ATM strategy with every tick. Which needless to say is not really what I want. I have tried a couple methods to prevent this and my study of the ATM Strategy example has not helped. Here are my code basics

    I am testing this with the market replay connection.



    ...
    private string atmStrategyId = string.Empty;
    private string orderId = string.Empty;
    ...


    if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    atmStrategyId = string.Empty;

    //entry criteria

    if (orderId.Length == 0 && atmStrategyId.Length == 0 && Low[0] < SMA(Close,period)[0])
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0,TimeInForce.Day, orderId, "WATTS",atmStrategyId);
    }
    Please help. I only want one entry per signal not as many contracts as my account equity will support.

    #2
    jcwolfe00,

    Notice how in the sample the reset line is after the entry condition and only at a specific point in time. Right now in your code you are just resetting every single time which is the reason why your entry condition continues to keep firing off true and making more trades.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      jcwolfe00,

      Notice how in the sample the reset line is after the entry condition and only at a specific point in time. Right now in your code you are just resetting every single time which is the reason why your entry condition continues to keep firing off true and making more trades.

      Alrighty, I think I understand what is going now. The code is re-iterating before the market order even gets filled and thus resetting, creating a new strategy again. Wash and repeat.

      Comment


        #4
        Alrighty, thanks Josh. I got it working properly now. However there seems to be an issue.


        The ATM strategy loads properly however it seems that it does not trail the stop the way it is saved in the strategy. When the ATM strategy loads does it load the stop strategy or is there an extra parameter I need to set?

        Comment


          #5
          When the ATM strategy is loaded whatever you have setup in the ATM takes over from that point on. Are you having difficulty setting up the ATM to perform the way you like? There are several tutorials in the Help Guide that demonstrate how to set up the ATM. Please search for the "Video Library". There should be some good ones in there.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            When the ATM strategy is loaded whatever you have setup in the ATM takes over from that point on. Are you having difficulty setting up the ATM to perform the way you like? There are several tutorials in the Help Guide that demonstrate how to set up the ATM. Please search for the "Video Library". There should be some good ones in there.

            Hmmmm...


            I have used this ATM strategy before on a discretionary basis and it trails the stop just fine. However when the script executes it the stop is not trailing at all.

            The ATM strategy is saved with the stop strategy settings I want. So I am a bit perplexed why the stop strategy is not implementing when executed by the script. The stop strategy is the whole point of me wanting the script to execute an ATM rather than simply placing a bracket in the script.

            Any ideas?

            Comment


              #7
              jcwolfe00,

              Please post an as simple as possible code snippet of what you have so far. Thanks.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Josh View Post
                jcwolfe00,

                Please post an as simple as possible code snippet of what you have so far. Thanks.

                Well it turns out I forgot that I have afternoon session entries and morning entries. The ATM entry criteria was only for the morning session. So it was not actually loading ATM strategy as i thought but just using the simple bracket info in the script. Hence no trailing stop

                but now I have new issues where the ATM strategy simply won't load..period.

                I am totally perplexed on this one.

                When this section:
                atmStrategyId = GetAtmStrategyUniqueId();
                orderId = GetAtmStrategyUniqueId();
                AtmStrategyCreate(...)
                is commented out as it is below my alert will sound when the entry occurs.
                however when it is not commented out NOTHING happens not even the alert sounding. So apparently something is wrong with that tiny snippet of code.




                private string atmStrategyId = string.Empty;
                private string orderId = string.Empty;


                if ( orderId.Length == 0 && atmStrategyId.Length == 0 && BuyEntry == true)
                {

                Alert(...);
                /*
                atmStrategyId = GetAtmStrategyUniqueId();
                orderId = GetAtmStrategyUniqueId();
                AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "WATTS", atmStrategyId);
                */
                }


                //Order Management
                if (orderId.Length > 0)
                {
                string[] status = GetAtmStrategyEntryOrderStatus(orderId);

                // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                if (status.GetLength(0) > 0)
                {
                // Print out some information about the order to the output window
                Print("The entry order average fill price is: " + status[0]);
                Print("The entry order filled amount is: " + status[1]);
                Print("The entry order order state is: " + status[2]);

                // If the order state is terminal, reset the order id value
                if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                orderId = string.Empty;
                }
                } // If the strategy has terminated reset the strategy id
                else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                atmStrategyId = string.Empty;

                The funny thing is i thought this was going to be an easy little stepping stone to a more complicated method for trailing my stop...but so far it has not been easy. Hopefully you can help.

                Comment


                  #9
                  Josh will reply back on Monday.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    jcwolfe00,

                    Please check your Control Center logs for errors while you are running your strategy.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Josh View Post
                      jcwolfe00,

                      Please check your Control Center logs for errors while you are running your strategy.

                      Alrighty. I am still befuddled.

                      When I check the logs it starts out with an error regarding
                      GetATMStrategyEntryOrderStatus() method error: Order id "blah blah" does not exist.

                      This function should not even run when the strategy first starts because orderid is initiated empty. The only place that function is called is

                      if (orderId.Length > 0)


                      So I tried commenting out the whole orderid section to see what would happen and got a puzzling error as well. It stated ATM strategies cannot be created on historical data. But I was testing the strategy in a sim account on live data.

                      Comment


                        #12
                        jcwolfe00,

                        If you don't mind please post your latest version of the code. I am not sure how your code has evolved since our last discussion.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Just as an update. Even though the strategy generated " ATM strategies cannot be created on historical data." with the order management section commented out, when an entry occurred the ATM strategy did execute. Not sure why it gave that error/warning.






                          private string atmStrategyId = string.Empty;
                          private string orderId = string.Empty;
                          private bool LE = false


                          protected override void OnBarUpdate()
                          {
                          //Long Entries

                          if (orderId.Length == 0 && atmStrategyId.Length == 0 && LE == true)
                          {
                          atmStrategyId = GetAtmStrategyUniqueId();
                          orderId = GetAtmStrategyUniqueId();
                          AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "WATTS", atmStrategyId);
                          }



                          //ORDER MANAGEMENT

                          if (orderId.Length > 0)
                          {
                          string[] status = GetAtmStrategyEntryOrderStatus(orderId);

                          // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                          if (status.GetLength(0) > 0)
                          {
                          // Print out some information about the order to the output window
                          Print("The entry order average fill price is: " + status[0]);
                          Print("The entry order filled amount is: " + status[1]);
                          Print("The entry order order state is: " + status[2]);

                          // If the order state is terminal, reset the order id value
                          if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                          orderId = string.Empty;
                          }
                          } // If the strategy has terminated reset the strategy id
                          else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                          atmStrategyId = string.Empty;

                          }

                          Comment


                            #14
                            ATM strategies are not meant to execute anything historically. You want to add this at the top of your OnBarUpdate().

                            Code:
                            if (Historical)
                                 return;
                            This is likely the stem of your error with orderId because your ATM strategy running historically is completely out of whack.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Josh View Post
                              ATM strategies are not meant to execute anything historically. You want to add this at the top of your OnBarUpdate().

                              Code:
                              if (Historical)
                                   return;
                              This is likely the stem of your error with orderId because your ATM strategy running historically is completely out of whack.

                              Thanks Josh, that did the trick. Greatly appreciated.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              633 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              567 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X