Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongLimit/EnterShortLimit Order not Reversing Position

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

    EnterLongLimit/EnterShortLimit Order not Reversing Position

    Hi,

    I am currently trying to code a strategy that allows me to enter trades using limit orders and also allows for me to reverse direction if there is an opposing direction signal. However, it seems that when I am in a position and there is supposed to be an EnterLongLimit or EnterShortLimit order to switch directions these orders do not place. I've replayed my strategy in Playback mode and have observed the first Limit entry order work but then when the strategy is supposed to reverse the opposing limit order does not get placed. I've also debugged my strategy with print statements to ensure that the if statement logic is properly running for the sections that have the Limit entry orders within them when reversing. As a result, I believe this might have something to do with the order handling rules but am unsure of what the actual issue is.

    Here are my two sections of code for the limit entry orders:

    Short Entries:

    if (UseStopCloseOppWickTargetR && !UseTwoPTLevels)
    {
    bearTarget = (entryPrice - ((shortCloseStopBodySL - entryPrice) * RProfitMultiplier));
    bearTarget2 = (entryPrice - ((shortCloseStopBodySL - entryPrice) * RProfitMultiplier2));

    Print("The target price for this trade is: " + bearTarget + " Time: " + Time[0]);
    Print("The stop loss for this trade is: " + shortCloseStopBodySL + " Time: " + Time[0]);

    SetProfitTarget("Short", CalculationMode.Price, bearTarget);
    SetStopLoss("Short", CalculationMode.Ticks, MaxSL, false);

    SetProfitTarget("Short2", CalculationMode.Price, bearTarget);
    SetStopLoss("Short2", CalculationMode.Ticks, MaxSL, false);

    Short1 = EnterShortLimit(0, true, DefaultQuantity, entryPrice, "Short");
    Short2 = EnterShortLimit(0, true, DefaultQuantity, entryPrice, "Short2");

    shortEntryCandleCount = 0; // Reset the counter when a new short order is placed
    }​​

    Long Entries:

    if (UseStopCloseOppWickTargetR && !UseTwoPTLevels)
    {
    bullTarget = (((entryPrice - longCloseStopWickSL) * RProfitMultiplier) + entryPrice);
    bullTarget2 = (((entryPrice - longCloseStopWickSL) * RProfitMultiplier2) + entryPrice);

    Print("The target price for this trade is: " + bullTarget + " Time: " + Time[0]);
    Print("The stop loss for this trade is: " + longCloseStopBodySL + " Time: " + Time[0]);

    SetProfitTarget("Long", CalculationMode.Price, bullTarget);
    SetStopLoss("Long", CalculationMode.Ticks, MaxSL, false);

    SetProfitTarget("Long2", CalculationMode.Price, bullTarget);
    SetStopLoss("Long2", CalculationMode.Ticks, MaxSL, false);

    Long1 = EnterLongLimit(0, true, DefaultQuantity, entryPrice, "Long");
    Long2 = EnterLongLimit(0, true, DefaultQuantity, entryPrice, "Long2");

    longEntryCandleCount = 0; // Reset the counter when a new long order is placed
    }​

    Thank you!

    #2
    Hello rjm1903,

    That would be expected, that is blocked by the internal order handling rules because you have targets working.

    Methods that generate orders to enter a position will be ignored if:

    •A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction

    Note: These rules do not apply to market orders, such as ExitLong() or ExitShort().

    ​To keep the targets you need to use market entries. To use the limit orders you would have to remove the targets.


    https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandl ingRulesThatReduceUnwantedPositions​

    Comment


      #3
      So there is no way to reverse position when using limit orders if I have profit targets and stop losses already set?

      Comment


        #4
        Hello rjm1903,

        Not while using the managed approach. By using a limit for a reversal you set up the script for a possible failure. You have two separate exits working at the same time for a single position. If the market moved fast it could end up filling a target or stop along with the entry leading to an in flight execution.

        Comment


          #5
          What about using an EnterLongStopMarket and EnterShortStopMarket order will these orders allow for me reverse position? Also will these orders be able to be placed at the same time in opposing places around a range (i.e. placing an EnterLongStopMarket order above the high of a range and simultaneously placing an EnterShortStopMar****rder at the low of the range)? Also, if one of those orders gets filled then does the opposing order automatically stop working? Or does it stay open until I cancel it?

          Thank you for your help on this!

          Comment


            #6
            Hello rjm1903,

            No that would be the same problem, the only options are what I had suggested or to use the unmanaged approach. If you use the unmanaged approach then you would also need to make sure that the reversal order and targets do not fill at the same time by cancelling the targets before submitting the reversal.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            55 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            132 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            73 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X