• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Prevent Closing a Position before Stop/Target Reached

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

    How to Prevent Closing a Position before Stop/Target Reached

    Hello,

    I have created a strategy that has a condition to go long or go short based on simple criteria and the long/short criteria are the inverse of each other. It is based on an SMA crossover strategy. I am using an EnterLong() and EnterShort() order for each condition and I have declared a SetStopLoss and SetProfitTarget value declared for each condition.

    If I am in a long position, I want to ensure that the position will not close until the target or stop value is reached, even if a short signal appears. In addition, if there is a short signal and I am currently in a long position, I also do not want NT to place another order to go short until the long has reached the target or stop (meaning I only want 1 futures contact to be bought a one time).

    Based on the current code (below), it seems that if I am in a long position and a short signal appears, it will close my position out and reverse. I am trying to figure out what rule I am missing to prevent the long form being closed or an additional order from being placed.

    Thanks for any information you can provide,
    -Dave



    protected override void Initialize()
    {


    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    CalculateOnBarClose = false;
    }


    protected override void OnBarUpdate()
    {


    if (long criteria)

    {
    EnterLong(1, "long");
    SetStopLoss(CalculationMode. ...);
    SetProfitTarget(CalculationMode ...);
    }

    // Condition set 2
    if (short criteria)
    {
    EnterShort(DefaultQuantity, "Short");
    SetStopLoss(CalculationMode ...);
    SetProfitTarget(CalculationMode ...);
    }

    #2
    Hello NewEngTrader,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Add Position.MarketPosition == MarketPosition.Flat to the conditions:
    Code:
    if (long criteria && Position.MarketPosition == MarketPosition.Flat)
    
    {
    EnterLong(1, "long");
    SetStopLoss(CalculationMode. ...);
    SetProfitTarget(CalculationMode ...);
    }
    
    // Condition set 2
    if (short criteria && Position.MarketPosition == MarketPosition.Flat)
    {
    EnterShort(DefaultQuantity, "Short");
    SetStopLoss(CalculationMode ...);
    SetProfitTarget(CalculationMode ...);
    }
    For information on Position please visit the following link: http://www.ninjatrader.com/support/h...7/position.htm

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NewEngTrader View Post
      Hello,

      I have created a strategy that has a condition to go long or go short based on simple criteria and the long/short criteria are the inverse of each other. It is based on an SMA crossover strategy. I am using an EnterLong() and EnterShort() order for each condition and I have declared a SetStopLoss and SetProfitTarget value declared for each condition.

      If I am in a long position, I want to ensure that the position will not close until the target or stop value is reached, even if a short signal appears. In addition, if there is a short signal and I am currently in a long position, I also do not want NT to place another order to go short until the long has reached the target or stop (meaning I only want 1 futures contact to be bought a one time).

      Based on the current code (below), it seems that if I am in a long position and a short signal appears, it will close my position out and reverse. I am trying to figure out what rule I am missing to prevent the long form being closed or an additional order from being placed.

      Thanks for any information you can provide,
      -Dave



      protected override void Initialize()
      {


      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;
      CalculateOnBarClose = false;
      }


      protected override void OnBarUpdate()
      {


      if (long criteria)

      {
      EnterLong(1, "long");
      SetStopLoss(CalculationMode. ...);
      SetProfitTarget(CalculationMode ...);
      }

      // Condition set 2
      if (short criteria)
      {
      EnterShort(DefaultQuantity, "Short");
      SetStopLoss(CalculationMode ...);
      SetProfitTarget(CalculationMode ...);
      }
      What you have written will do what you want. There have been many arguments and much caviling on these fora about the fact that in the presence of protective orders, the Managed approach for orders will not reverse a trade on the same bar if CalculateOnBarClose is true, or indeed at all, if there is no cancellation of said orders.

      Comment


        #4
        Thank you

        Thank you for your feed back and suggestions!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by williamzz, Today, 03:10 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cabum, 09-25-2018, 06:46 AM
        8 responses
        229 views
        0 likes
        Last Post koganam
        by koganam
         
        Started by saeed, Today, 02:07 PM
        6 responses
        12 views
        0 likes
        Last Post NinjaTrader_Heath  
        Started by 7robert, Today, 01:40 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by bortz, Today, 12:57 PM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_PatrickH  
        Working...
        X