Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop below the bar before the entry bar. Please help.

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

    Stop below the bar before the entry bar. Please help.

    Hi there,

    I've probably spent the last 3 hours trying to figure this out on both NT7 and NT8... as you can guess i'm new to NT.

    How do I set an initial stop to be say 100 pips below the bar before the entry bar. In fact, is it possible to use any indicator or bar value with an initial stop, either through the builder or using code? All I can manage is to set a simple stop based on price, pips etc.

    I want the stop to be sent to the broker at the same time as the order. Not a trailing stop or anything like that.

    I figure the stop needs to be in the OnStateChange() method. I tried assigning Low[0]-0.01 to a variable in OnBarUpdate() at entry, then using that variable in SetStopLoss, but I can't get it to work. That's just one of a 100 different ways i've tried it. Please help!

    #2
    Hello kabes223,

    Thanks for your post and welcome to the forums!

    If you are just starting out in NinjaTrader, in both NinjaTrader7 and NinjaTrader8 you can use the "Set" methods. SetStopLoss() and SetProfitTarget(). These will place OCO (One Cancels Other) linked orders at the moment the entry order is filled.

    In NinjaTrader 7 you would use these methods in the Initialize() method and from there they are automatically applied to any entry order made.

    In NinjaTrader8 you would use these in the OnStateChange() method specifically in State.Configure. They will perform in the same manner as NinjaTrader7.

    I will post links to both methods in both versions below and I would encourage you to test them with the examples shown. You can of course do other things with them such as setting dynamically but it is best to start easy and understand what works and how. The links each contain a lot of information and tips that will assist in understanding the use and limits.

    NT7: http://ninjatrader.com/support/helpG...etstoploss.htm
    NT7: http://ninjatrader.com/support/helpG...ofittarget.htm
    NT8: http://ninjatrader.com/support/helpG...etstoploss.htm
    NT8: http://ninjatrader.com/support/helpG...ofittarget.htm

    Comment


      #3
      Hi Paul,

      Thanks for the speedy reply.

      I've read through a good chunk of the guide a few times now, not to mention countless forum posts and videos. I get that I have to use SetStopLoss inside the else if (State == State.Configure), and that I can configure it using price, pips etc, but how do I use indicator and bar values with the stop? Or can that only be done as a dynamic trailing stop inside OnBarUpdate()?

      Thanks for your help.

      Comment


        #4
        Hello kabes223,

        Thanks for your reply.

        Correct, you can use the methods within the OnBarUpdate() to allow for dynamic changes, provided that when you are flat that you set the stop or profit target to known values OR that prior to placing an order you first set the values of the stop and target. You have to do this because these set methods will remember that last setting used and that may be inappropriate for the very next entry made so it is critical to ensure they are at the values you want before allowing an entry order.

        For example if you use SetStopLoss(CalculationMode.Price, SMA(50)[0]); when the trade is over SetStopLoss will be at the last value used, if then place a new order, that last set price may be way wrong for that next order. This is where you want to ensure of what the values are by setting them appropriately before the next entry. You can mix modes, in once instance you might use ticks in another you can use price.

        Comment


          #5
          Hi Paul,

          Sorry, I'm not sure that I actually want a "dynamic" stop though. I don't want the stop to change at all during the open order. I want to place one stop along with the entry order, and say I want the stop to be at the low of the bar before the actual entry bar. Isn't that a static stop? And are you saying that's not possible using OnStateChange()? I attached an example of the stop (red lines).

          Is it possible for you to put this in code for me please? I'm really trying to get my head around how a stop like this actually looks in code. Thanks again.
          Attached Files

          Comment


            #6
            Hello kabes223,

            Thanks for your reply.

            To place the fixed stop below the low of the bar, here is a code example, in OnBarUpdate:

            if (Your conditions for entry)
            {
            SetStopLoss(CalculationMode.Price, Low[1] - 1 * TickSize); // 1 tick below the low
            your entry order here:
            }

            Note that the sequence is to set the stop level before placing the entry order because SetStoploss, once used, will remember the last setting applied.

            Comment


              #7
              Great, thanks Paul.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              54 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              131 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              73 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              44 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              49 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X