Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop loss below entry bar

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

    Stop loss below entry bar

    Hi need a little help on the coding. Wantstop loss to be 2 ticks below Low[0]

    So far I have:
    protected override void Initialize()
    {
    SetProfitTarget("", CalculationMode.Ticks, 20);
    SetStopLoss("", CalculationMode.Ticks, 10, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss("",CalculationMode.Ticks, 10, false);
    }
    // Condition set 1
    if (Open[2] > Close[2]
    && Open[1] > Close[1]
    && Close[0] + 4 * TickSize > Open[2])
    {
    SetStopLoss(CalculationMode.Ticks, Low[0] - 2);
    EnterLong(DefaultQuantity, "");
    }
    }

    Thanks in advance

    #2
    Hello Benww604,

    Thank you for your post.

    You would want to use 2 * TickSize to get the instruments ticksize and multiply it by the number of ticks you wish to set it to.

    SetStopLoss(CalculationMode.Ticks, Low[0] - 2 * TickSize);
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by benww604 View Post
      Hi need a little help on the coding. Wantstop loss to be 2 ticks below Low[0]

      So far I have:
      protected override void Initialize()
      {
      SetProfitTarget("", CalculationMode.Ticks, 20);
      SetStopLoss("", CalculationMode.Ticks, 10, false);

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if (Position.MarketPosition == MarketPosition.Flat)
      {
      SetStopLoss("",CalculationMode.Ticks, 10, false);
      }
      // Condition set 1
      if (Open[2] > Close[2]
      && Open[1] > Close[1]
      && Close[0] + 4 * TickSize > Open[2])
      {
      SetStopLoss(CalculationMode.Ticks, Low[0] - 2);
      EnterLong(DefaultQuantity, "");
      }
      }

      Thanks in advance
      You are trying to set your stop loss to a price. Use CalculationMode.Price then.

      Comment

      Latest Posts

      Collapse

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