Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Condition Builder StopLoss Functionality

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

    Condition Builder StopLoss Functionality

    Hi,

    I'm using the condition builder to get up to speed coding.

    I'm trying to set the LOW of the bar (Low[1]) before the entry bar as the stoploss point on a LONG trade is this possible in Condition Builder?

    So Enter long current bar and set stoploss to previous bar low..

    Help appreciated...

    #2
    Hello Godzilla,

    Here is a video demonstration on how to use an Indicator value as a Stop loss order by setting an Indicators value to a user variable that you may change a little bit and instead of getting a value of an Indicator you may check and get the value of the Low 1 bar ago.

    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    Let us know if you have any further questions.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello Godzilla,

      Here is a video demonstration on how to use an Indicator value as a Stop loss order by setting an Indicators value to a user variable that you may change a little bit and instead of getting a value of an Indicator you may check and get the value of the Low 1 bar ago.

      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


      Let us know if you have any further questions.
      Hi JC,

      The video was great but I'm not sure what my problem is now as upon building the Strategy in the Builder...then click View Code I can see the relevant lines:

      SetStopLoss("",CalculationMode.Price,Variable0,Fal se);
      Variable0= Low[1];
      CalculateonBarClose = true;


      Note my entry and set-up conditions are perfect...just that the Stoploss is "not" getting hit at all?
      My target gets hit no problem.

      My Strategy StopLoss level = low of previous bar if I enter long on current bar.

      Appreciate your help!!

      Comment


        #4
        Hello Godzilla,

        Would you mind sharing your strategy so that I can investigate this further?

        Reply -> Go Advanced -> Click the Paperclip in the top toolbar
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Condition Builder Stoploss Functionality - code added

          Hi Cal,

          Code file added as requested.

          Appreciate your support - thank you..
          Attached Files

          Comment


            #6
            Hi Godzilla,

            Thanks for the screenshot.

            From the screenshot I see that you are setting the Stop Loss and Profit Target in Initialize(). This method Initialize() is run when you add your indicator to a chart but is not run after this.

            The Profit Target uses ticks. This means is will be relevant to the entry price (a number of ticks behind the entry). The Stop Loss uses a defined exact price. However, this price is only set once at Initialize(). At that time OnBarUpdate has not run yet. This means that Variable0 at that point is still 0 and this is where the Stop Loss is being set.

            Are you making this strategy with the Strategy Wizard or is this script unlocked for editing?

            If this is unlocked, try moving the SetStopLoss() call to OnBarUpdate just after Variable0 is updated. (Though its not really necessary to use Variable0 at that point if your code is unlocked.)

            For example:

            if (High[0] < High[1]
            && High[1] < High[2]
            && Position.MarketPosition == MarketPosition.Flat)
            {
            SetStopLoss("", CalculationMode.Price, Low[1], false);
            EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "");
            }

            Just a heads up. You may want to be sure that the low of the previous bar is lower than the current price. If its not the stop could be ignored.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              Could I just confirm with you that moving the SetStopLoss function AFTER the OnBarUpdate area (as you have suggested) will LOCK in the Low[1] price (EntryPrice - Low[1] = Risk amt) after entry or will the Low[1] update as the Stoploss level on each new bar?

              Ideally I want to LOCK the Low[1] on the entry bar as a HARD stoploss and will use other exit techniques to exit the trade as it progresses?

              Comment


                #8
                Hello Godzilla,

                It depends where you put it.

                The code in my example will not update on each new bar. It will be set just before the order is made to the correct price. Then the order will be entered and the stop loss will be placed at the correct price.

                If you want the stop loss updated on each new bar, do not put the SetStopLoss call inside of a branching command (if statement).
                That being said, if you are constantly setting the stop loss to the same price on every bar this seems a bit unnecessary..

                Also, if you plan to use a stop loss and then also use some sort of exit call, be sure that only one of them can be triggered at a time. If both trigger simultaneously you can get an overfill or an opposite position.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                558 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                324 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                545 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                547 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X