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 cre8able, Today, 01:16 PM
        2 responses
        9 views
        0 likes
        Last Post cre8able  
        Started by chbruno, 04-24-2024, 04:10 PM
        3 responses
        48 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by samish18, Today, 01:01 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by WHICKED, Today, 12:56 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by WHICKED, Today, 12:45 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X