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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X