Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting a stop on prior bars

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

    Setting a stop on prior bars

    Sorry if this is elementary, but I am just starting to learn Ninja. I am trying to figure out how to set a stop in relation to the high/low of two bars back and I cannot figure it out.

    For instance, I have two bars in a row, each with the close higher than the previous bar, thus two green bars. So I go long at the beginning of the next bar, but I want to set the stop loss to be the low of two bars ago (the first green bar in this example). I have also thought about setting the stop at the low of two bars ago minus another 10 cents or so, but I figure for programming purposes I can figure out how to do that once I know how to set the stop at the low/high (high for a short that is red/red) of the bar two bars back.

    Any help would be greatly appreciated.

    Thanks in advance.

    #2
    Hi riskymove. A NinjaScript trainee will respond later in the day. Thanks for your patience.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Stop loss 1 tick below low of previous bar for long and 1 tick above for short

      I am new to Ninja Trader & I would like to know how I can implement this simple stop loss strategy. Naturally I would like to move this stop in my favor after each bar is formed. Firstly is this possible to do using the Wizard and if so, how, if not can this be done using NinjaScript?

      Thank you in advance,
      suprsnipes

      Comment


        #4
        Could you post the reply please. I am interested in the answer too. Thanks.

        Comment


          #5
          Hello Riskymove,


          I am sorry no one got to your post earlier.

          Here is how you set a stop loss at the low two bars behind the current bar:
          if(....your condition here....)
          {
          SetStopLoss("mySignal", CalculationMode.Price, Low[2], false);
          EnterLong(DefaultQuantity, "mySignal");
          }
          DenNinjaTrader Customer Service

          Comment


            #6
            How to only Calculate Once?

            Originally posted by NinjaTrader_Ben View Post
            Hello Riskymove,


            I am sorry no one got to your post earlier.

            Here is how you set a stop loss at the low two bars behind the current bar:
            if(....your condition here....)
            {
            SetStopLoss("mySignal", CalculationMode.Price, Low[2], false);
            EnterLong(DefaultQuantity, "mySignal");
            }
            I would like it to set a hard stop loss at the low or high of the previous bar (depending whether I am going long or short) when I establish a position, but I do not want it to move the stop dynamically like a trailing stop. How would I do that? Thanks in advance for your help.

            Comment


              #7
              Hello,


              You will need to build a condition for setting your stop. Something like this:

              if(...your conditions to set a new stop here...
              && set_stop == true)
              {
              SetStopLoss(...);
              set_stop = false;
              }

              Then a seperate condition for entering:

              if(...your conditions to enter here...)
              {
              EnterLong(...);
              {

              Then at some point you want to reset the set_stop to true so you can move your stop. Like this:

              if(...some condition to set stop here...
              && set_stop == false)
              {
              set_stop = true;
              }
              DenNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              580 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              335 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              102 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X