Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change the quantity of an ATM strategy

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

    Change the quantity of an ATM strategy

    As far as I understand it, the only way I can alter the quantity of an ATM strategy entry is by altering the underlying ATM strategy.

    However, I would like to be able to change this programatically according to certain criteria which need to be calculated on-the-fly by NinjaScript. I can alter other components of the ATM within NinjaScript (e.g. LimitPrice, StopPrice etc), but not the quantity! Or am I missing something obvious?

    Thanks In advance.

    #2
    Welcome to our forums here - you would then need to call the AtmStrategyCreate() with different templates for your qty changes as needed.

    Comment


      #3
      Bertrand,

      Thanks for the welcome - the forums look very helpful, I will try and be more than just a leach as time goes on ;-)

      I did think of that as a work around. However, the NinjaScript strategy I am trying to create 1) is run against a wide variety of markets and 2) has variable position sizing. Thus, the entry size could be 236 or 378 or 1234 etc. I guess I could create a large number of ATM strategies with quantities of 200, 400, 600, 800 etc and then I would be approximately correct with my quantities. This would probably be sufficient for now.

      I am using a straightforward AutoChase order. Another solution would be to code the auto-chase strategy into my NinjaScript strategy. This would give my the advantage of having control over other elements of the strategy, and would be a more elegant long-term solution. Has anyone tried to do this already?

      I guess the way to go about writing my own custom AutoChase order would be by using OnMarketData() combined with GetCurrentAsk/Bid. I would then cancel and re-enter my EnterLongLimit order with each change in the Bid (or can I modify my existing order)?

      Any help/suggestions welcome.

      Comment


        #4
        You're welcome - correct in this case I would also favor coding out the ATM natively in your NinjaScript strategy as the Enter() methods / SubmitOrder could work with any integer qty.

        Unfortunately I'm not aware of an implementation of the AutoChase directly in NinjaScript, if you run the script on CalculateOnBarClose = false and resubmit orders as needed (just call the same order again withe the same name but different price) it should be what you look for here.

        Comment


          #5
          OK thanks very much..... that should be enough to get me started.

          I will probably just use the simpler method (ATM strategies with quantities of 200, 400, 600 etc) for now, and then if things work out as planned I will try and code up the AutoChase as a script....The fact I don't know C# or NinjaScript doesn't help, I'm just winging it for now lol..... I will post back here when I run into problems ;-)

          Comment


            #6
            You're welcome, be sure then to check into our 'SampleAtmStrategy' script installed per default with your NT.

            Comment


              #7
              OK how does this look? It is an attempt to re-create the auto-chase function, but using a standard order type rather than an ATM strategy. The script just goes long/short if Open>Close. The interesting part is after the "OnMarketData"....

              Let me know if you think this is a good/safe way of doing things, and if there are any sort of sanity checks etc that should be in place.

              Code:
              #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.Gui.Chart;
              using NinjaTrader.Strategy;
              #endregion
              
              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
                  /// <summary>
                  /// 
                  /// </summary>
                  [Description("")]
                  public class OnMarketDataTest : Strategy
                  {
                      #region Variables
                      // Wizard generated variables
                      // User defined variables (add any user defined variables below)
                      public double AskPrice;
                      public double BidPrice;
                      //Offset is the other way round to an ATM offset e.g a positive offset is inside the spread, negative is outside
                      public double Offset = 0.01;
                      public int Quantity = 100;
                      private IOrder entryOrder     = null;
                      #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()
                      {
                      
                          if (Close[0] > Open[0]) {
                              ExitShort("ShortEntry");
                              entryOrder = EnterLongLimit(Quantity, GetCurrentBid() + Offset, "LongEntry");
                              //Print (Instrument.FullName + "EnteringLongLimit:" + MyLimitPrice);
                          }
                          
                          if (Open[0] > Close[0]) {
                              ExitLong("LongEntry");
                              entryOrder = EnterShortLimit(Quantity, GetCurrentAsk() - Offset, "ShortEntry");
                              //Print (Instrument.FullName + "EnteringShortLimit:" + MyLimitPrice);
                          }
                          
                      }
                      
                      protected override void OnMarketData(MarketDataEventArgs e)
                      {
                      
                          //We only need to be looking at the Bid/Ask if we actually have an unfulled order:
                          if (entryOrder != null && entryOrder.OrderState != OrderState.Filled ) {
                          
                              //Then if we have another bid, and it has changed, and we have a long order, we need to change it:
                              if (e.MarketDataType == MarketDataType.Bid && BidPrice != e.Price && entryOrder.OrderAction == OrderAction.Buy) {
                                  
                                     BidPrice = e.Price;                            
                                  //Print ("NewBid: A:"  + AskPrice + " B:" + BidPrice);
                                  //Print ("Changing " + entryOrder.OrderAction + Instrument.FullName + " Order.... NewLimitPrice =" + MyLimitPrice);
                                  entryOrder = EnterLongLimit(Quantity, BidPrice + Offset, "LongEntry");
                                          
                              }
                              //then the reverse: if we have an ask, and it has changed, and we have a short order:
                          else if (e.MarketDataType == MarketDataType.Ask && AskPrice != e.Price && entryOrder.OrderAction == OrderAction.SellShort ) {
                              
                                   AskPrice = e.Price;
                                  //Print ("NewAsk: A:"  + AskPrice + " B:" + BidPrice);
                                  //Print ("Changing " + entryOrder.OrderAction + Instrument.FullName + " Order.... NewLimitPrice =" + MyLimitPrice);
                                  entryOrder = EnterShortLimit(Quantity, AskPrice - Offset, "ShortEntry");
                              
                              }
              
                          }
                          
                      }        
                      
                  
                      #region Properties
                      #endregion
                  }
              }

              Comment


                #8
                AntiMatter, I briefly looked over your code and didn't see you resetting your IOrders anywhere. If you are working with IOrders, please look over the help guide page on them and review the how to submit protective orders sample, which demonstrates how/when to reset the IOrders.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Thanks for the help. All running well now.

                  I am running this though IB. Something I have noticed which is undesirable: If the limit price of my order gets altered when I have a partial fill, the order acts as a completely new order. Thus, I end up paying the minimum commission twice. This can be irritating when e.g. there is only a few shares left to fill.

                  When I submit a REL order through TWS (similar to the Auto Chase feature), then I only pay the minimum commission once, even after multiple fills at different prices.

                  Any ideas? Any easy work around? Does the Auto Chase ATM also suffer from this drawback?
                  Last edited by AntiMatter; 02-07-2011, 11:32 AM.

                  Comment


                    #10
                    You're welcome AntiMatter, are you referring to getting partials on the entry and then you change the price and this would create different individual exit orders instead of qty amendments?

                    Comment


                      #11
                      I'm talking about just the entry order e.g:

                      1) I have a buy order for 328
                      2) 300 gets filled --> i pay $1.50 commission (300 * 0.005)
                      3) The Bid price changes.
                      My script changes the limit price, and the order gets chaned
                      4) The final 28 shares get filled --> I pay $1 in commision. With a REL order on TWS, I would only pay the extra $0.14

                      Comment


                        #12
                        Thanks for the clarification - in IB this would be one order then as offset / order price change is built into the REL type, thus only charged at one order for you.

                        Comment


                          #13
                          OK thanks for the clarification.
                          I guess this is my confusion over how NinjaTrader and the API communicate, and how this relates to orders.

                          To clarify: I would observe the same problem when using an Auto Chase order, for example?

                          Comment


                            #14
                            Hello,

                            Since bert has been working with you on this I will have him respond first thing in the morning when he gets bak into the office.

                            Thanks for your patience.
                            BrettNinjaTrader Product Management

                            Comment


                              #15
                              OK I know I'm being a terrible pedant ;-) However this will add up to a chunk of change over the long term....

                              Does the Auto Chase feature suffer from this problem? E.g. paying multiple minimum commission on partially filled orders which get changed?

                              Is there any way for me to get commission info for a position/trade within ninja script?

                              Thanks

                              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