Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SL and TP reset back to original values on each candle if i move them manually

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

    SL and TP reset back to original values on each candle if i move them manually

    In my strategy i use on my initial entry into a position and check to make sure i am not already in a position

    if(marketposition.flat)
    {
    EnterLong()
    SetStopLoss()
    SetProfitTarget()
    }

    When the strategy enters a position, it sets all the criteria. When i try to manually adjust the SL or TP on the chart trader, it always resets it back to the original value on a new candle. How do i prevent this? Why does it reset back to the original value?

    #2
    Hello sofortune,

    This is expected behavior.

    See the forum posts below about using isLiveUntilCancelled with Entry and Exit orders to keep orders alive without resubmitting these.
    Hello guys, I'm submitting entry orders using managed approach. After the entry order is filled I tried to move the stop order manually, but the order goes back to the same original price. Is there some way to be able to disable this behavior and be able to modify price of an order (stop or target) under managed approach?


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have revised my code from using SetProfitTarget and SetStopLoss to use ExitLongLimit and ExitLongStopLimit. When I test the strategy, it seems none of the longlimit or stoplimit orders are being placed.

      Any ideas why?

      Code:
      for (int i = 0; i < EntriesPerTrade; i++)
      {
      // Enter long position with a unique name and set the take profit and stop loss levels
      EnterLong(1, "Long " + i);
      ExitLongLimit(0, true, 1, Position.AveragePrice + TakeProfitLevels[i] * TickSize, "Long TP " + i, "Long " + i);
      ExitLongStopLimit(0, true, 1, Position.AveragePrice - InitialSLAmount, Position.AveragePrice, "Initial SL " + i, "Long " + i);
      //SetProfitTarget("Long" + i, CalculationMode.Ticks, TakeProfitLevels[i]);
      //SetStopLoss("Long" + i, CalculationMode.Ticks, InitialStopLoss, isSimulatedStop);
      positionNames.Add("Long " + i); // Add entry name to list
      }
      stopLossesModified = false;​

      Comment


        #4
        I got this error from trace log:

        8/4/2023 3:50:30 AM Strategy '30s GRaB Scalp/-1': Entered internal SubmitOrderManaged() method at 8/4/2023 3:50:30 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long 3' FromEntrySignal=''
        8/4/2023 3:50:30 AM Strategy '30s GRaB Scalp/-1': Entered internal SubmitOrderManaged() method at 8/4/2023 3:50:30 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=25.00 StopPrice=0 SignalName='Long TP 3' FromEntrySignal='Long 3'
        8/4/2023 3:50:30 AM Strategy '30s GRaB Scalp/-1': Ignored SubmitOrderManaged() method at 8/4/2023 3:50:30 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=25.00 StopPrice=0 SignalName='Long TP 3' FromEntrySignal='Long 3' Reason='This was an exit order but no position exists to exit'
        8/4/2023 3:50:30 AM Strategy '30s GRaB Scalp/-1': Entered internal SubmitOrderManaged() method at 8/4/2023 3:50:30 AM: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=-10.00 StopPrice=0 SignalName='Initial SL 3' FromEntrySignal='Long 3'
        8/4/2023 3:50:30 AM Strategy '30s GRaB Scalp/-1': Ignored SubmitOrderManaged() method at 8/4/2023 3:50:30 AM: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=-10.00 StopPrice=0 SignalName='Initial SL 3' FromEntrySignal='Long 3' Reason='This was an exit order but no position exists to exit'​
        Last edited by sofortune; 08-08-2023, 11:47 AM.

        Comment


          #5
          Hello sofortune,

          ExitLongLimit() and ExitLongStopLimit() would need to be submitted after the position has changed.

          The position has not changed by the time this code is reached. It takes time for the order to be constructed, then submitted to the brokerage, the order to be accepted, then become working, then for there to be a trade executed and the order to be filled, and then for the broker to report back to ninjatrader the order has filled, and then for the position to change.

          Submit these orders from OnPositionUpdate() or OnExecutionUpdate() after the entry order has filled, or if these must be sent from OnBarUpdate(), put this in a different condition set that checks the position is Long.

          See the ExitMethodsShortSample linked from post # 2 for an example that checks the position in OnBarUpdate() on lines 77 to 80.
          See the ProfitChaseStopTrailExitOrdersExample linked below for an example that submits the orders in OnExecutionUpdate() on lines 227 and 237.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          46 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          66 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X