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

Is there a way to set "SetStopLoss" below the last close price?

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

    Is there a way to set "SetStopLoss" below the last close price?

    I am trying to set a stop-loss and profit on a long/short positions. The current settings I have is below:

    SetStopLoss(@"Long", CalculationMode.Ticks, 0, false);
    SetProfitTarget(CalculationMode.Ticks, X);

    I would like to take a profit on X tickets and set a stop-loss one tick below the last closed bar. What there a way to achieve this on long/short position or any documentation that could help?
    Last edited by pyraxic; 11-18-2020, 01:20 AM.

    #2
    Hi pyraxic,

    Try something with calculationmode.price and use Low[0] to find the low value of the previous bar. Then remove 1 tick or 0,25 point: Low[0]-0,25 if you are long.

    Code:
    protected override void OnBarUpdate()
    {
    SetStopLoss(@"8", CalculationMode.Price, Low[0]-TickSize, false);
    }
    And here there is lot of documentation: https://ninjatrader.com/support/helpGuides/nt8/?low.htm

    ​​​​​​​Best regards
    Last edited by Ben01660; 11-12-2020, 04:19 AM.

    Comment


      #3
      Hello pyraxic,

      Thanks for your post and welcome to the NinjaTrader forums!

      Forum member Ben01660 has provided a solution assuming you are using a Ninjascript based strategy. To add on, you can specify as many ticks as you wish along these lines Low[0] - 3 * TickSize (set 3 ticks below the low of the current bar. To access the previous bar you would use Low[1]).

      If you are using the Strategy Builder then this would not be possible as the Set methods in the Strategy Builder can only use fixed values and not variables such as Low[].
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thank you! I have a few follow-up questions.

        What does @8 means in "SetStopLoss(@"8".."? I am assuming that I'll be using the following for short positions? Given that my stop-loss is one tick above the last closed bar.

        SetStopLoss(@"8", CalculationMode.Price, Low[0]+1, false);

        Do I have the SetProfitTarget(CalculationMode.Ticks, X); correctly? I would like to take profit at X ticks from the entry position?
        Last edited by pyraxic; 11-18-2020, 01:20 AM.

        Comment


          #5
          I am using
          Code:
          SetStopLoss(@"EntryLong", CalculationMode.Price, Close[0]-1, false);
          but it still says largest losing trade is $725 instead of $100 for ES Futures. It's my understanding the I am using close[0] which is the previous closed bar and the stop-loss is 1 tick below the previous closed bar. Low[0] gives me the exact same result while using the Strategy Analyzer.

          Comment


            #6
            Hello pyraxic,

            Thanks for your replies.

            "What does @8 means in "SetStopLoss(@"8".."? " With reference to the help guide here: https://ninjatrader.com/support/help...etstoploss.htm that would be the "from entry signal" parameter meaning that this specific stop will only apply to an entry with the name of "8"

            " I am assuming that I'll be using the following for short positions? Given that my stop-loss is one tick above the last closed bar. SetStopLoss(@"8", CalculationMode.Price, Low[0]+1, false);" In that example you are adding 1 point of the instrument to the Low of the current bar. You would need to use Low[0] + 1 * TickSize in order to set 1 tick above the low of the current bar.

            "Do I have the SetProfitTarget(CalculationMode.Ticks, 4); correctly? I would like to take profit at 4 ticks from the entry position?" Yes, that would provide a 4 tick profit target and will automatically adjust to above the entry if long or below the entry if short.

            "SetStopLoss(@"EntryLong", CalculationMode.Price, Close[0]-1, false);" - In this example now you are subtracting 1 point from the close of the current bar.

            Please eview the help guide documents listed below to better understand what you are trying to do:



            Paul H.NinjaTrader Customer Service

            Comment


              #7
              In the code provided below from Ben, Where would the "protected override void OnBarUpdate()" be placed relative to where the Conditions and SetProfitTarget is placed? Just below the SetProfitTarget line, or other? thx

              protected override void OnBarUpdate()
              {
              SetStopLoss(@"8", CalculationMode.Price, Low[0]-TickSize, false);
              }

              Comment


                #8
                Hello Mizzy2021,

                Thanks for your post and welcome to the NinjaTrader forums!

                It would depend on what you are trying to do.

                The Set method can be placed in the OnStateChange() method if you intend for them to not change. For example, if you always wanted a 20 tick profit target and a 10 tick stoploss on every entry, you can set these once in OnStateChange().

                Alternately, if you wanted to set them relative to a specific bar or indicator value then you would have to set/use them in the OnBarUpdate() method. Typically you would set them prior to the entry for their initial values. You can adjust them while in the trade if needed.

                You may want to review the links in Post #6 for further information.
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Jimmyk, 01-26-2018, 05:19 AM
                6 responses
                835 views
                0 likes
                Last Post emuns
                by emuns
                 
                Started by jxs_xrj, 01-12-2020, 09:49 AM
                6 responses
                3,291 views
                1 like
                Last Post jgualdronc  
                Started by Touch-Ups, Today, 10:36 AM
                0 responses
                10 views
                0 likes
                Last Post Touch-Ups  
                Started by geddyisodin, 04-25-2024, 05:20 AM
                11 responses
                62 views
                0 likes
                Last Post halgo_boulder  
                Started by Option Whisperer, Today, 09:55 AM
                0 responses
                9 views
                0 likes
                Last Post Option Whisperer  
                Working...
                X