Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting the Stop Loss to update

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

    Getting the Stop Loss to update

    Cannot get stop loss to update.

    I have been looking at past threads on updating stop losses to attempt to get my initial stop loss to update. I believe I need to set a new order to cancel the initial stop loss once I am in the trade, however, even if I completely take out the initial stop loss I cannot get the Stop Loss to update as it should. Any help is greatly appreciated.

    protectedoverridevoid Initialize()
    {
    SetStopLoss(CalculationMode.Ticks,
    100);

    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] > Close[1]
    && Close[
    1] > Close[2])
    {
    EnterLong(DefaultQuantity,
    "");
    }
    //Change Trail Stop to Min last two bars
    {
    SetTrailStop(CalculationMode.Price, MIN(Low,
    2)[0]);

    CalculateOnBarClose =
    true;
    }

    }

    #2
    I think I may have got a little further, but at this point, I am not really sure what is going wrong. 1) It never cancels my initial stop and then 2) since the initial stop isn't cancelled, the trailing stop never starts.

    protectedoverridevoid Initialize()
    {
    SetStopLoss (CalculationMode.Ticks,
    100);

    CalculateOnBarClose =
    true;

    }

    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] > Close[1]
    && Close[
    1] > Close[2]
    && ToTime(Time[
    0]) > ToTime(8, 44, 0))
    {
    EnterLong(DefaultQuantity,
    "");
    }

    //Exit Stop Loss if more than two bars since entry
    if (BarsSinceEntry() > 2)

    {
    ExitLongStop(
    1);
    }
    //Change Trail Stop to Min last two bars
    {
    SetTrailStop(CalculationMode.Price, MIN(Low,
    2)[0]);

    CalculateOnBarClose =
    true;
    }

    }

    Comment


      #3
      The reason is you cannot mix SetStopLoss() with SetTrailStop(). You will need to stick with one or the other.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        I changed the initial stop to be a trailing stop, so that both were trailing stops but the system never updated the stop. It does cancel the inital stop, but it will not set the new trailing stop to the low of the last two bars after you have been in the trade more than 2 bars. Still cannot figure out what I am doing wrong.
        Thanks again for any help.

        protectedoverridevoid Initialize()
        {
        SetTrailStop (CalculationMode.Ticks,
        100);

        CalculateOnBarClose =
        true;

        }

        ///<summary>
        /// Called on each bar update event (incoming tick)
        ///</summary>
        protectedoverridevoid OnBarUpdate()
        {
        // Condition set 1
        if (Close[0] > Close[1]
        && Close[
        1] > Close[2]
        && ToTime(Time[
        0]) > ToTime(8, 44, 0))
        {
        EnterLong(DefaultQuantity,
        "");
        }

        //Exit Stop Loss if more than two bars since entry
        if (BarsSinceEntry() > 2)

        {
        ExitLongStop(
        2);
        }
        //Change Trail Stop to Min last two bars
        {
        SetTrailStop(CalculationMode.Price, MIN(Low,
        2)[0]);

        CalculateOnBarClose =
        true;
        }

        }

        Comment


          #5
          Try using TraceOrders = true to see what is happening. http://www.ninjatrader-support.com/v...ead.php?t=3627

          Also, you do not need this line in the OnBarUpdate() method:

          CalculateOnBarClose =
          true;

          And your bracketing is probably wrong. You do want to bracket SetTrailStop() and CalculateOnBarClose out of the blue. You only need brackets when using if-statements, loops, etc.
          Last edited by NinjaTrader_JoshP; 09-15-2008, 11:29 AM.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Does traceorders work during backtesting or only in real-time? I have it in Initialize but nothing prints during BT.

            Comment


              #7
              It will work in both. If you have nothing printing then you need to check your Control Center logs for errors.

              Add additional Print()s throughout your code to track what is going on better. Please see this article: http://www.ninjatrader-support.com/v...ead.php?t=3418
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

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