Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting Trade at Entry when using "SetStopLoss"

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

    Exiting Trade at Entry when using "SetStopLoss"

    I added code to my strategy so that my stop loss is set to the last high pivot (for a short entry) or the last low pivot for a long entry. I have kept track of the value of the last pivot using variable "PvtHigh" or "PvtLow".

    I have used the Print command to check the value of "PvtHigh" and "PvtLow" and it is indeed what it should be on each bar of the chart.

    I have the following lines in my code:

    if (Position.MarketPosition == MarketPosition.Short)
    {

    SetStopLoss("MomoSE1", CalculationMode.Price, PvtHigh, false);
    SetStopLoss("MomoSE2", CalculationMode.Price, PvtHigh, false);

    }

    But as long as this line remains in the strategy my positions are exited on the same bar as they are entered on, and at the same price. This happens even though the high or low of that bar never touches the value held by the variable "PvtHigh" or "PvtLow".

    If I comment out the line with the SetStopLoss command the position remains open until it exits via a technical stop.

    Am I doing something wrong?

    Thanks,

    rsi77

    #2
    rsi77,

    Please submit the stop losses before you open your position to ensure they are attached with the properly value in time.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      OK, so that worked. I added the SetStopLoss once inside the buy loop, but before the actual lines that placed the order. Now my stoploss is working at the pivot levels.

      But what if I want to change the stop loss after I have entered the trade.

      I know how to exit at market once certain conditions have been met. Can I no longer use the SetStopLoss command if the order is already filled?

      thanks,

      rsi77

      Comment


        #4
        Please see this reference sample for how to make modifications: http://www.ninjatrader-support2.com/...ead.php?t=3222
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I've also posted a framework based on the link Josh is pointing you to.

          It's called ProfitTargetTrailingStop_1.01b
          It adds a Stop Limit, Profit Target and Trailing Stop that advances on close of bar or every tick according to CalculateOnCloseOfBar true or false within your auto trade strategy.
          It is a simple implementation that tries to emulate the ATM trailing stop 1st level.
          I am currently working on a 3 level trailing stop to emulate the full ATM trailing stop tool.

          ProfitTargetTrailingStop_1.01b download

          Cheers
          Chris Long

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          647 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X