Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stair-step STOPS

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

    Stair-step STOPS

    I am looking for your expert help again.
    My goal is to enter a position with a full stop and then move the stop twice as the trade goes in my favor. My command to adjust the stop is ignored. (I’ve not added the second stair-step yet). Entry is done in OnExecution() whereas the stop is done during OnBarUpdate(). I trade CalculateOnBarClose(false) and NT7.0.1000.1 . Below i show setting the stop the first time.
    #region Variables
    private int stopLoss = 12;
    private IOrder entryOrderLong = null;
    private IOrder stopOrder = null;

    protected override void Initialize()
    {
    SetStopLoss("R1Long",CalculationMode.Ticks,stopLoss,false);
    }
    protected override void OnBarUpdate()
    {
    if((Position.MarketPosition==MarketPosition.Long&&
    Close[0] >= (Position.AvgPrice + (stopLoss*TickSize)))) {
    if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice) {
    stopOrder = ExitLongStop(
    0, true, stopOrder.Quantity, Position.AvgPrice, "R1Long Stop", "R1Long"); }}



    #2
    ( i haven't figured out how to make a post big enough, so this is 2 of 2)
    Below i show the command to adjust the stop - this is ignored.
    if (Position.MarketPosition == MarketPosition.Long){
    // This is where i suspect i am having my problem
    if ((High[0] >= (Position.AvgPrice + (4*TickSize)))
    && (firstStopJumpDone == false)) {
    firstStopJumpDone = true;
    stopOrder = ExitLongStop(stopLoss-4,"R1 Long Stop", "R1 Long");
    }}
    Thank you

    Comment


      #3
      Hello JulieC,

      Thanks for sharing the code snippet. You're combining Set statements with ExitLongStop and one of these will be ignored. Please see the following link > Internal Order Handling rules.


      Methods that generate orders to exit a position will be ignored if:
      • A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
      • A position is open and an order submitted by a set method (SetStopLoss() for example) is active

      You can monitor for ignored orders by adding TraceOrders = true; to the initialize method and view output through tools > output window.

      We have a dedicated sample for modifying stop loss orders dynamically. Best bet is to follow this sample closely at first and then start adding complexity once you've verified behavior is what you expect. This is available here:
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        I finally got it !!! This little project has been a killer for me, but what broke me through the barrier was Ryan's quote:

        "Best bet is to follow this sample closely at first and then start adding complexity once you've verified behavior is what you expect."

        Indeed, I was making it far too complex and it needed to be simplified first. Specifically, i enter with 2 independent positions (named to keep them straight) but the stop strategy is the same for both. So only one stop strategy is needed - i was trying to use 2 independent stop commands.

        Lesson: Use Initialize() method for initial static SetTrailStop, then dynamically change the stop inside the OnBarUpdate() method using the exact same command terminology that was used inside Initialize(). (Of course, the "double value" argument is different in these two commands.)

        Thanks for steering me in the right direction.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        631 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        566 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X