Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy is exiting a position twice !

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

    Strategy is exiting a position twice !

    I have made an initial strategy in Ninjatrader that is trading when an outside bar occurs, but sometimes when the initial position is exited ... a new entry trade is send as well .. due to the fact that the

    Exit point of the first trade is sometimes exactly at the same moment that a new outside bar occurs and thus a new entry trade should be entered.

    This is not a problem.

    However, i have noticed that sometimes Ninjatrader can’t handle this and will try to exit the initial position TWICE ! + also enter into a new position....In the end i will be left with a position that will not be exited...

    Also... In my code i have defined : short, exit short, long and exit long....

    I don’t know where the “Close position” that is causing the problem comes from, because it is not in the code...

    In this example i made one short entry, one short exit, one long entry and one long exit..
    However, dus to an extra BUY order to "Close position"of the initial short trade, i am left in the end with a buy position...

    INTC Sell 1 25.69 20:29:30 short
    INTC Buy 1 25.73 20:31:35 close position
    INTC Buy 1 25.73 20:31:35 long
    INTC Buy 1 25.73 20:31:35 exit short
    INTC Sell 1 25.73 20:35:34 exit long

    Does anybody know if i am doing something wrong ?

    I have added a screenshot of the conditions to enter or exit a position
    Attached Files

    #2
    marcus,

    You may run into overfills with this sort of strategy. Its important to have your exit long separate from your enter short and exit short separate from your enter long in a strategy like this. I would suggest doing something like this.

    if ( My_long_entrance conditions_are_true )
    {
    EnterLong();
    }
    else if ( My_short_exit_conditions_are_true )
    {
    ExitShort();
    }

    This prevents one or the other from being called at the same time.
    Last edited by NinjaTrader_AdamP; 08-22-2012, 01:34 PM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      HI Adam,

      Thanks for your reply.

      I am a newbie with Ninjatrader...

      I try to look up the script that you noted, to check how i could seperate long exit
      from enter short, however i couldnt find it..

      Do you know how i should apply this to the code that i have or where i can read about
      seperating the long exit from short entry...

      Comment


        #4
        marcus,

        If you can post your code as text in this forum I can show you an example.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          hi adam, below is a copy of the code i have created so far :


          #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>
          /// Buyifhigh OUTSIDE
          /// </summary>
          [Description("Buyifhigh OUTSIDE ")]
          public class Buyathigh1845 : 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()
          {

          CalculateOnBarClose = false;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (Close[0] > High[1]
          && Low[0] < Low[1]
          && VOLMA(14)[0] > 4000)
          {
          EnterLong(DefaultQuantity, "long");
          }

          // Condition set 2
          if (Close[0] < Low[1])
          {
          ExitLong("exitlong", "long");
          }

          // Condition set 3
          if (High[0] > High[1]
          && Close[0] < Low[1]
          && VOLMA(14)[0] > 4000)
          {
          EnterShort(DefaultQuantity, "short");
          }

          // Condition set 4
          if (Close[0] > High[1])
          {
          ExitShort("exitshort", "short");
          }
          }

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

          Comment


            #6
            marcus,

            Please see the code attached.

            Code:
            // Condition set 1
            if (Close[0] > High[1]
            && Low[0] < Low[1]
            && VOLMA(14)[0] > 4000)
            {
            EnterLong(DefaultQuantity, "long");
            }
            else if (Close[0] > High[1])
            {
            ExitShort("exitshort", "short");
            }
            
            // Condition set 3
            if (High[0] > High[1]
            && Close[0] < Low[1]
            && VOLMA(14)[0] > 4000)
            {
            EnterShort(DefaultQuantity, "short");
            }
            else if (Close[0] < Low[1])
            {
            ExitLong("exitlong", "long");
            }
            Adam P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mattbsea, Today, 05:44 PM
            0 responses
            3 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            31 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Started by tkaboris, Today, 05:13 PM
            0 responses
            2 views
            0 likes
            Last Post tkaboris  
            Started by GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,282 views
            0 likes
            Last Post Leafcutter  
            Started by WHICKED, Today, 12:45 PM
            2 responses
            20 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Working...
            X