Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM Strategy in Automated Strategy

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

    ATM Strategy in Automated Strategy

    How do I get to use an ATM strategy in a automated strategy, meaning to have an ATM strategy as your order submission instead of EnterLong(DefaultQuantity, "" I see you have a sample atmstrategy but when adding this there is no where to select the atm strategy you want to us.
    Can anyone point me in the right direction or give me a sample?

    Cheers

    #2
    Hi geotabs, you would be using the AtmStrategyCreate() here to trigger your entry - http://www.ninjatrader.com/support/h...gy_methods.htm

    For a working sample and helpful code structure, please check into the preinstalled 'SampleAtmStrategy' we ship with NinjaTrader per default.

    Comment


      #3
      Thanks Bertrand
      I have looked at the Sample AtmStrategy but how do you get to select what atm strategy you want to use from a drop down box?
      {
      atmStrategyId = GetAtmStrategyUniqueId();
      orderId = GetAtmStrategyUniqueId();
      AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
      }
      Do you just remove the AtmStrategyTemplate and leave the ""?
      I am sorry but I have never programed before and am learning from others and what they have created.

      Cheers

      Comment


        #4
        You could unfortunately not have it pickup, what you selected - you code in the template name the strategy would then use - "AtmStrategyTemplate" > this would use the AtmStrategyTemplate you created on the DOM or ChartTrader.

        You could also make this a user string input to gain more flexibility.

        Comment


          #5
          I'm also confused about this. So does this mean you name the ATM what you want, and simply reference it in the code?

          Comment


            #6
            So I tried to apply a Private String in the variables

            private string selectatm = "3contracts5,10 open target";

            And used this for the atm order code

            AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
            TimeInForce.Day, GetAtmStrategyUniqueId(), "3contracts5,10 open target" ,
            "LongATM"+count);

            Where am I going wrong, it does not give me a selectatm in the parameters box?

            Thanks

            Comment


              #7
              As far as I know, there is no way to select the ATM in the parameters box. Or is there?

              Comment


                #8
                I'm hoping so, I have an indicator that has 2 Private String to allow for sound alert and text alert, all I have to do is go to the parameters and copy and paste from the NT sound file and it will play whatever I pasted in the box, same with text, so I'm hoping, else I'll have to have about 10 different strategies.

                Comment


                  #9
                  Originally posted by outstretchedarm View Post
                  I'm also confused about this. So does this mean you name the ATM what you want, and simply reference it in the code?
                  Yes, this is correct. If you name the template "2 stop 1 target" you reference "2 stop 1 target" in code.

                  Originally posted by geotabs View Post
                  So I tried to apply a Private String in the variables

                  private string selectatm = "3contracts5,10 open target";

                  And used this for the atm order code

                  AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
                  TimeInForce.Day, GetAtmStrategyUniqueId(), "3contracts5,10 open target" ,
                  "LongATM"+count);

                  Where am I going wrong, it does not give me a selectatm in the parameters box?

                  Thanks
                  your private string will not be available in the parameter box. You will only have the ATM Strategy template name. In your case, 3contracts5,10 open target
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    Originally posted by geotabs View Post
                    I'm hoping so, I have an indicator that has 2 Private String to allow for sound alert and text alert, all I have to do is go to the parameters and copy and paste from the NT sound file and it will play whatever I pasted in the box, same with text, so I'm hoping, else I'll have to have about 10 different strategies.
                    The NinjaScript strategy is not available from the ATM Strategy parameters window. You will have to enable the strategy by right clicking on the chart and selecting Strategies. Keep in mind you cannot run a NS strategy from the same chart you have Chart Trader enabled.
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Thanks Matthew, but what did NinjaTrader_Bertrand mean by "You could also make this a user string input to gain more flexibility."
                      I'm new to programming and would like to learn from you guys.

                      Cheers

                      Comment


                        #12
                        Bertrand was meaning to make it a public string which you could access from the Strategy parameters itself.

                        You would need to expose this variable as a public user input.

                        Please see our Reference Sample on Creating User Defined Input Parameters:

                        Last edited by NinjaTrader_Matthew; 12-06-2012, 01:17 PM.
                        MatthewNinjaTrader Product Management

                        Comment


                          #13
                          I must say, i am failing to implement the code from the sample ATM strategy into any working code of mine. Exactly which part of this ginormous strategy does one have to copy and paste into an existing code to make it utilize the ATM?

                          Code:
                          // 
                          // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
                          // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
                          //
                          
                          #region Using declarations
                          using System;
                          using System.ComponentModel;
                          using System.Diagnostics;
                          using System.Drawing;
                          using System.Drawing.Drawing2D;
                          using System.Xml.Serialization;
                          using NinjaTrader.Cbi;
                          using NinjaTrader.Data;
                          using NinjaTrader.Indicator;
                          using NinjaTrader.Strategy;
                          #endregion
                          
                          
                          // This namespace holds all strategies and is required. Do not change it.
                          namespace NinjaTrader.Strategy
                          {
                              /// <summary>
                              /// 
                              /// </summary>
                              [Description("")]
                              public class SampleAtmStrategy : Strategy
                              {
                                  #region Variables
                          		private string	atmStrategyId		= string.Empty;
                          		private string	orderId				= string.Empty;
                                  #endregion
                          
                                  /// <summary>
                                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                                  /// </summary>
                                  protected override void Initialize()
                                  {
                                      CalculateOnBarClose = true;
                                  }
                          		
                                  /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                                  protected override void OnBarUpdate()
                                  {
                          			// HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies"
                          
                          			// Make sure this strategy does not execute against historical data
                          			if (Historical)
                          				return;
                          
                          
                          			// Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
                                      // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
                          			if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
                          			{
                          				atmStrategyId = GetAtmStrategyUniqueId();
                          				orderId = GetAtmStrategyUniqueId();
                          				AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId);
                          			}
                          
                          
                          			// Check for a pending entry order
                          			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;
                          
                          
                          			if (atmStrategyId.Length > 0)
                          			{
                          				// You can change the stop price
                          				if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                          					AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
                          
                          				// Print some information about the strategy to the output window
                          				Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
                          				Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
                          				Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
                          				Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
                          			}
                                  }
                          
                                  #region Properties
                                  #endregion
                              }
                          }
                          thanks!

                          Comment


                            #14
                            For best practices, you'd want to implement most of that. If you're unsure what a function is doing, you check the documentation on the ATM Strategy methods:



                            I suppose the line you're looking for to initialize an ATM Strategy would be the AtmStrategyCreate()
                            MatthewNinjaTrader Product Management

                            Comment


                              #15
                              If I simply wanted to add a few conditions to that existing code (like a macd crossover for example), at what lines would I "insert" it?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              647 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X