Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Reverse Position Issue and NT logic

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

    Reverse Position Issue and NT logic

    Hi there,

    I am having problems with my strategy I will post the code in a minute . The idea of the system is it goes long and short with limit orders and has profit targets as well . The issue I am having is where as an example i am short from a signal and the profit target is not hit but a long signal is generated in the opposite direction say 3 bars later , my system is not taking the long position . In fact whenever a profit target is not met and a signal occurs in the opposite direction the system does not take the signal , I thought NT logic was supposed to handle the closing of positions first and then open the others , here is the code :

    /// <summary>
    /// Simple Long Short Test
    /// </summary>
    [Description("Simple Long Short Test")]
    public class New : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int target = 3; // Default setting for Target
    // 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()
    {
    SetProfitTarget("", CalculationMode.Ticks, Target);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] > High[2]
    && Close[1] <= High[2]
    && Close[1] < High[3])
    {
    EnterLongLimit(DefaultQuantity, Close[0] + 1 * TickSize, "");
    }

    // Condition set 2
    if (Close[0] > High[2]
    && Close[1] <= High[3]
    && Close[0] >= High[3])
    {
    EnterLongLimit(DefaultQuantity, Close[0] + 1 * TickSize, "");
    }

    // Condition set 3
    if (Close[0] < Low[2]
    && Close[1] >= Low[2]
    && Close[1] > Low[3])
    {
    EnterShortLimit(DefaultQuantity, Close[0] + -1 * TickSize, "");
    }

    // Condition set 4
    if (Close[0] < Low[2]
    && Close[1] >= Low[3]
    && Close[0] <= Low[3])
    {
    EnterShortLimit(DefaultQuantity, Close[0] + -1 * TickSize, "");
    }


    }

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

    #2
    Hello raker22,

    Thanks for your post.

    In the managed approach, only EnterLong() and EnterShort() will close a current position and open a new one, using market orders.

    Please check the "log" tab of the Ninjatrader control center, you likely will have an error message advising one , or more, orders have been ignored. Here is a link to the internal order handling rules for the managed approach: http://ninjatrader.com/support/helpG...d_approach.htm check the section: Internal Order Handling Rules that Reduce Unwanted Positions
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks I have read the manual and understand the logic , so what you are saying is I need to cancel the order first before submitting an order in the opposite direction ?
      If so is there a sample code in which I can use as a template to do this .
      thx tim

      Comment


        #4
        Hello,

        That would be correct, we have a sample that demonstrates both storing an order to a variable and also Cancelling that order here: http://ninjatrader.com/support/forum...ad.php?t=18890

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,602 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        12 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X