Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss()

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

    SetStopLoss()

    Hi,

    Sometimes the SetStopLoss is send even when the condition is not meet.
    I have used the Print() funtion and the strategy do not enter into the block of code in bold, but for some reason the SL is send anyway.

    Any Clue why is happening?

    I use daily bars

    Thanls a lot


    if (Position.MarketPosition==MarketPosition.Flat)
    {
    if (GAP_Up==true)
    {
    EnterShort();
    SetProfitTarget(CalculationMode.Price,TP_Level);

    if (Low[-1]>Close[0])
    {
    SetStopLoss(CalculationMode.Ticks,SL_Level);
    }


    GAP_Up=false;

    }


    }

    #2
    Hi CJS,

    Set statements will use the last value that is set. If this condition occurs once, then that is the value used for SetStopLoss unless you set a different value.

    If you want to conditionally send a stop order, ExitLongStop() and ExitShortStop() are better for this.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by "CJS" View Post
      Hi,

      Sometimes the SetStopLoss is send even when the condition is not meet.
      I have used the Print() funtion and the strategy do not enter into the block of code in bold, but for some reason the SL is send anyway.

      Any Clue why is happening?

      I use daily bars

      Thanls a lot


      if (Position.MarketPosition==MarketPosition.Flat)
      {
      if (GAP_Up==true)
      {
      EnterShort();
      SetProfitTarget(CalculationMode.Price,TP_Level);

      if (Low[-1]>Close[0])
      {
      SetStopLoss(CalculationMode.Ticks,SL_Level);
      }


      GAP_Up=false;

      }


      }
      Emphasis mine. Low[-1] is meaningless in NinjaScript, and is probably causing an unpredictable error.

      Comment


        #4
        Hi,

        Koganam

        I now that. Cose I use daily bars for this backtest, I look at the futures bars in order not to entry one day after I want. I asure you that this is normal and really useful.

        That is not the problem.

        Thanks for reading my post and try to help me.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 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
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X