Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 RideMe, 04-07-2024, 04:54 PM
        6 responses
        31 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,281 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        19 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Tim-c, Today, 02:10 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X