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

Stop Loss Offset

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

    Stop Loss Offset

    How would one put a stop loss 2 points under the lowest low for the last 5 bars (for a long)?

    #2
    Try SetStopLoss(MIN(Low, 5)[0] - 2 * TickSize)
    If TickSize is not what you want you can also try Instrument.MasterInstrument.PointValue.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Do I call that once in Initialize, or just before I enter the long?
      Edit: Nix that, I have RTFM.
      Last edited by CraigC; 06-29-2008, 02:46 AM.

      Comment


        #4
        I now get 'buy stop or buy stop limit orders can't be placed below market'

        Comment


          #5
          Right buy stop orders cannot be placed there. Please see this tip: http://www.ninjatrader-support.com/v...ead.php?t=3271
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            I think I sorted it, the proper syntax is

            SetStopLoss(CalculationMode.Price, MAX(High, 5)[0] + stopLoss * TickSize);

            Comment


              #7
              Hey Craig and Josh, thanks for posting up how to do this, I've been sweating over this for two full days...Now I've tried your syntax and I can't quite work out why it doesn't do the calculation it should. I have

              SetStopLoss(CalculationMode.Price, MIN(Low, 5)[0] - 6 * TickSize);

              So theoretically it should take the lowest low for the last five candles and then subtract a further 6 pips to set the stop loss - what I want is one pip below the lowest low of the last five candles and then I'm adding the 5 pips broker's spread on - which gives me my 6 below. But when I run it and read off the charts, for example, a buy is marked and the low of the candle before it is 1.8364, but the stop loss exits the trade at 1.8365. That's 1 pip above the low of the last candle not 6 pips below it. I'm sure there's a good explanation, but I can't fathom it right now. Can you help?

              Comment


                #8
                Hi Red Fish,

                Best way to check is to print values instead of trying to visualize it from the chart. Reason for printing is so you know for sure what the system thinks the value is.

                Try printing out the value for your MIN(Low, 5)[0] - 6 * TickSize and then comparing it to the value that your stop loss is at.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Josh, thanks for your reply! I'm sorry to sound a bit dumb. I wrote this
                  Print(MIN(Low, 5)[0] - 6 * TickSize); below the SetStopLoss line, but I don't get anything in the output window. What am I doing wrong?

                  Comment


                    #10
                    Sorry, I cleared the output window and I reapplied the strategy to the charts again, now it is showing me a string of numbers. So how do I judge these numbers...what am I looking for??

                    Comment


                      #11
                      Do this.
                      Print(Time[0] + " " + MIN(Low, 5)[0] + " " + TickSize);
                      You will get two numbers. Use your calculator to find your stop loss value between those values. Then figure out the time that your stop loss is submitted and compare the value of your stop loss to the value that your prints come out as. They should match.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Josh! So I can confirm the values are right, phew! So really it's the visualisation that is off? Does that mean that the numbers will come out right in the end then?

                        Comment


                          #13
                          Visualization is not necessarily wrong. It may just be that you are correlating values from the wrong bar to be what you think the stop loss should be.

                          What you want to do is find your entry trade. Look at the chart and determine what you wish the stop loss should be in theory. Then look at the values you did earlier and see if those values match up with what you want them to be. If they match you are golden. You may be off by a bar to the left or right due to miscounting when you say "5 bars back". Just come back to your code and adjust the 5 accordingly to match up the stop loss with what you want.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Josh, now I've put in my other conditions and try and run this from the strategy analyser it gives me a blank screen when I select this strategy. If I set my stop loss to 25 ticks

                            SetStopLoss(CalculationMode.Ticks, 25);

                            it gives me the normal screen to fill in my parameters. But if I alter the same test strategy to

                            SetStopLoss(CalculationMode.Price, MIN(Low, 5)[0] - 6 * TickSize);

                            it gives me a blank screen. If I try and run it with the blank screen it tells me NT needs to close down. I have even uninstalled and reinstalled NT and did it again but it does the same thing. If I then amend it back to a simple 25 ticks stop loss it allows me to run it.

                            Comment


                              #15
                              >>SetStopLoss(CalculationMode.Price, MIN(Low, 5)[0] - 6 * TickSize);

                              You can not access an indicator value in Initialize() method. Please see resulting error(s) in the log. Please try moving your logic to OnBarUdpate() method.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Mizzouman1, Today, 07:35 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Radano, 06-10-2021, 01:40 AM
                              20 responses
                              616 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by i019945nj, 12-14-2023, 06:41 AM
                              6 responses
                              67 views
                              0 likes
                              Last Post i019945nj  
                              Started by aa731, Today, 02:54 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by BarzTrading, Today, 07:25 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post BarzTrading  
                              Working...
                              X