Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is This Possible?

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

    Is This Possible?

    I currently use a strategy that has discretionary entries (at least I can't imaging a way to code it...) but has purely mechanical exits based on indicators. As my exits have always been a weak point for me, I have found much greater success in using mechanical exits and stick to my entries which are quite good.
    What I would like to build is a strategy that I can enter manually, but when I do, my position size is automatically calculated for me and entered and my exit is automatically taken care of also.
    Does this sound like a pipe dream???

    #2
    Does anybody offer a coding service that could handle this type of thing??

    Comment


      #3
      No, this is not a dream however, this is not possible at the current time. This is on our list for future enhancement though.
      RayNinjaTrader Customer Service

      Comment


        #4
        Fantastic, can't wait!

        Comment


          #5
          If you know how to code your exits already, it is not that difficult to work around.

          Instead of an automated entry, you could simply tell the strategy what position to start out at when you put it on the chart.

          Let the strategy enter that position somewhere on historical data and it will simply perform a simulated entry, and from then on you can let it manage your real position.

          Just take care to test what happens when you reload strategies on the chart. I always find this to be the time when most things potentially break, as a lot of internal variables get reset.

          Comment


            #6
            Thanks Gert74.
            Sounds great, I could definitely work with that. I am not really sure how to set it up though, could you provide a little more info?

            Comment


              #7
              I think what gert74 means is just have the strategy start up with an open strategy position that would match your manually entered position. The strategy would then proceed in all its calculations and exit the position whenever it deems necessary. When the strategy exits it will exit your real position too.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                just have the strategy start up with an open strategy position
                I'm interested in this as well, and was going to start a thread with the same question. I often enter positions manually and then would like the position "monitored" and exited when conditions are met.

                What is a reasonable way to have the strategy start up with an open position that matches the actual account open position? Can the strategy be "seeded" with this information via user parameters? If not how can this be accomplished within NT?


                Thanks,
                Guy
                TraderGuy
                NinjaTrader Ecosystem Vendor - EMS

                Comment


                  #9
                  This could be done however, there is not a simple approach. We would need to give this some thought on how a strategy could be coded and then deployed. Will add this to my list of reference samples. This will not happen in the short term.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Fundamentally, all you need are two parameters. One for the market position (using the built in MarketPosition enum data type will give you a nifty little dropdown) and quantity (your basic integer).

                    If you're a lazy programmer (like me), you could simply use a negative quantity for short positions, and then you would need only one parameter.

                    Now, your strategy will need to enter that position at some point before it can exit it again. What we want is for the strategy to enter the position somewhere on the historical part of the data series (so that it will be a simulated entry) and exit in realtime (to trigger a live order to the broker).

                    In theory you could enter at any point like the first bar of the chart. However, if you want you could add another parameter with a time or price point to enter at if you want to make it resemble your real entry for some reason.

                    That's the basic principle of it.

                    Just code your strategy to only look for your exit signal on realtime data, and you're good to go.

                    Comment


                      #11
                      Originally posted by gert74 View Post
                      Fundamentally, all you need are two parameters. One for the market position (using the built in MarketPosition enum data type will give you a nifty little dropdown) and quantity (your basic integer).

                      If you're a lazy programmer (like me), you could simply use a negative quantity for short positions, and then you would need only one parameter.

                      Now, your strategy will need to enter that position at some point before it can exit it again. What we want is for the strategy to enter the position somewhere on the historical part of the data series (so that it will be a simulated entry) and exit in realtime (to trigger a live order to the broker).

                      In theory you could enter at any point like the first bar of the chart. However, if you want you could add another parameter with a time or price point to enter at if you want to make it resemble your real entry for some reason.

                      That's the basic principle of it.

                      Just code your strategy to only look for your exit signal on realtime data, and you're good to go.
                      Thanks for all your feedback everyone, I appreciate the help.

                      I have had an attempt at creating a strategy, but it does not quite work as intended. Would anyone mind commenting on the 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.Strategy;
                      #endregion

                      // This namespace holds all strategies and is required. Do not change it.
                      namespace NinjaTrader.Strategy
                      {
                      /// <summary>
                      /// Executes a Long trade with donchian Channel Exits
                      /// </summary>
                      [Description("Executes a Long trade with donchian Channel Exits")]
                      [Gui.Design.DisplayName("Long Trade")]
                      public class LongTrade : Strategy
                      {
                      #region Variables
                      // Wizard generated variables
                      private int donchianPeriod = 24; // Default setting for DonchianPeriod
                      private int quantity = 5; // Default setting for Quantity
                      // User defined variables (add any user defined variables below)
                      #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 = false;
                      }

                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                      // Condition set 1
                      if (Position.MarketPosition == MarketPosition.Long)
                      {
                      EnterLong(Quantity, "");
                      }

                      // Condition set 2
                      if (GetCurrentBid() < DonchianChannel(DonchianPeriod).Lower[0])
                      {
                      ExitLong("", "");
                      }
                      }

                      #region Properties
                      [Description("Donchian Channel Periods")]
                      [Category("Parameters")]
                      public int DonchianPeriod
                      {
                      get { return donchianPeriod; }
                      set { donchianPeriod = Math.Max(1, value); }
                      }

                      [Description("Quantity to buy")]
                      [Category("Parameters")]
                      public int Quantity
                      {
                      get { return quantity; }
                      set { quantity = Math.Max(1, value); }
                      }
                      #endregion
                      }
                      }

                      Comment


                        #12
                        #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>
                        /// Executes a Long trade with donchian Channel Exits
                        /// </summary>
                        [Description("Executes a Long trade with donchian Channel Exits")]
                        [Gui.Design.DisplayName("Long Trade")]
                        public class LongTrade : Strategy
                        {
                        #region Variables
                        // Wizard generated variables
                        private int donchianPeriod = 24; // Default setting for DonchianPeriod
                        private int quantity = 5; // Default setting for Quantity
                        private bool simEntry = false;
                        // User defined variables (add any user defined variables below)
                        #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 = false;
                        }

                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                        // Condition set 1
                        if (Position.MarketPosition == MarketPosition.Long) <--this won't work in entering you your simulated position because Position is your strategy position and not your account position
                        {
                        EnterLong(Quantity, "");
                        }


                        // try this instead
                        if (Historical && simEntry == false)
                        {
                        EnterLong(Quantity, "");
                        simEntry = true;
                        }


                        // Condition set 2
                        if (GetCurrentBid() < DonchianChannel(DonchianPeriod).Lower[0])
                        {
                        ExitLong("", "");
                        }
                        }

                        #region Properties
                        [Description("Donchian Channel Periods")]
                        [Category("Parameters")]
                        public int DonchianPeriod
                        {
                        get { return donchianPeriod; }
                        set { donchianPeriod = Math.Max(1, value); }
                        }

                        [Description("Quantity to buy")]
                        [Category("Parameters")]
                        public int Quantity
                        {
                        get { return quantity; }
                        set { quantity = Math.Max(1, value); }
                        }
                        #endregion
                        }
                        }
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Perfect!! Thank you so much. I could have wasted days trying to figure that out...

                          Comment


                            #14
                            Great. Glad it worked out for you.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Copied and modified the code for a short trade, but it does not exit the trade... any ideas?

                              #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>
                              /// Exits Trade on Donchian Cross
                              /// </summary>
                              [Description("Exits Trade on Donchian Cross")]
                              [Gui.Design.DisplayName("Short Donchian")]
                              public class ShortDonchian : Strategy
                              {
                              #region Variables
                              // Wizard generated variables
                              private int donchianPeriod = 24; // Default setting for DonchianPeriod
                              private int quantity = 5; // Default setting for Quantity
                              private bool simEntry = false;
                              // User defined variables (add any user defined variables below)
                              #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 = false;
                              }

                              /// <summary>
                              /// Called on each bar update event (incoming tick)
                              /// </summary>
                              protected override void OnBarUpdate()
                              {
                              // Condition set 1
                              if (Historical && simEntry == false)
                              {
                              EnterShort(Quantity, "");
                              simEntry = true;
                              }
                              // Condition set 2
                              if (GetCurrentBid() > DonchianChannel(DonchianPeriod).Upper[0])
                              {
                              ExitShort("", "");
                              }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              597 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              343 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              556 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              555 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X