Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Auto Strategy Order Management Issue

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

    Auto Strategy Order Management Issue

    Newbie to Auto Trading...

    Threw together a simple moving average cross strategy that should exit the open position and enter a new position in the opposite direction. (1 contract)

    The strategy started with 1 contract but then when it got a signal to exit and enter the opposite direction it added a contract. So it exited 1 contract then it entered 2 contracts. Later it exited 2, then entered 3. Still later it exited 3 and entered 5. This went on until the strategy bombed out at 11 contracts.

    Is this an issue within the strategy itself? Or with demo?

    The strategy is very basic with a start time added and simple order management.

    Any help will be greatly appreciated. Thanks in advance!

    #2
    Hello MiniDowTrader,
    Thanks for your post.
    Seems an issue with the strategy, but to pin point the issue I need to see the strategy. Can you please post your code in the forum, if not, then can you please send it to
    Support[AT]ninjatrader[DOT]com with Attn: Joydeep in the subject line and with the link of this thread.

    I look forward assisting you.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      {
      /// <summary>
      /// Five Ten SMA Crosses
      /// </summary>
      [Description("Five Ten SMA Crosses")]
      public class AutoTradeGlobex : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      // 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()
      {
      Add(SMA(5));
      Add(SMA(10));
      Add(SMA(5));
      Add(SMA(10));

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (ToTime(Time[0]) >= ToTime(3, 0, 0)
      && CrossAbove(SMA(5), SMA(10), 1))
      {
      ExitShort("", "");
      EnterLong(DefaultQuantity, "");
      }

      // Condition set 2
      if (ToTime(Time[0]) >= ToTime(3, 0, 0)
      && CrossBelow(SMA(5), SMA(10), 1))
      {
      ExitLong("", "");
      EnterShort(DefaultQuantity, "");
      }
      }

      #region Properties
      [Description("")]
      [GridCategory("Parameters")]
      public int MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        Hello MiniDowTrader,
        Thanks for the code.

        You can only use EnterLong/EnterShort and no need to write ExitLong/ExitShort codes.
        EnterLong will close any short position and enter a long position. Reverse for EnterShort. So no need for Exit Long/Short codes.

        Please do let me know if that fixes your issue.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thank you Joydeep!

          Comment


            #6
            Hello MiniDowTrader,
            Have a nice day and please do let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              I changed the order management issue, and that is working fine, but I have another issue with my strategy.

              Per the code, I would like it to start at 3:00 am Eastern US time. (my time zone)

              Last evening I enabled the strategy on the YM and the NQ at 9:40 pm. But both filled an order on the first indicator signal instead of waiting until 3:00 to enter on the first signal. This also happened the previous evening on the YM at around 11:00 pm. In this instance, the strategy ignored all indicator signals until after 3:00 am and then filled the next signal.

              Have I made a mistake with the time settings in the strategy?

              Thanks for all your help!

              Comment


                #8
                Hello MiniDowTrader,
                Currently your code wont take any trades from midnight to 3:00AM. Thus, if a signal is generated at 11:00PM, the order will be executed. If the signal is generated at 2:00AM NO orders will be executed.

                In order to filter it further you have to specify an "in between time", like place order between 3:00AM and 9:00AM.
                So the code will look like
                Code:
                if (ToTime(Time[0]) >= ToTime(3, 0, 0)
                [COLOR="Green"]&& ToTime(Time[0]) <= ToTime(9,0,0)[/COLOR]
                && CrossAbove(SMA(5), SMA(10), 1))
                {
                EnterLong(DefaultQuantity, "");
                }
                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Ah, yes. I see the error in my ways.

                  Thank you again Joydeep. I will make the changes and try again this evening.

                  Comment


                    #10
                    Hello,
                    Glad you spotted the error. Please do let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ghoul, Today, 06:02 PM
                    2 responses
                    12 views
                    0 likes
                    Last Post ghoul
                    by ghoul
                     
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    44 views
                    0 likes
                    Last Post jeronymite  
                    Started by Barry Milan, Yesterday, 10:35 PM
                    7 responses
                    20 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    10 responses
                    180 views
                    0 likes
                    Last Post jeronymite  
                    Started by DanielSanMartin, Yesterday, 02:37 PM
                    2 responses
                    13 views
                    0 likes
                    Last Post DanielSanMartin  
                    Working...
                    X