Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Place Order After Price Drops 20 Ticks Below Previous High

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

    #61
    Hello maaxk,

    You could remove the condition set that checks the price falling 20 ticks, and just set the limit price each time the current high series is set to the market price minus 20 ticks if this is what you want.

    Note, you would need to set the price for the order to a variable, and submit the order in a separate condition set on each new bar to keep it alive.

    The example below demonstrates setting the price to a variable and submitting an order using the variable as a price on each new bar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #62
      Hello Chelsea,

      Look we have already decided the current high, so the only thing we need to do is enter a long position once it drops by -20 ticks.
      Also
      You could remove the condition set that checks the price falling 20 ticks, and just set the limit price each time the current high series is set to the market price minus 20 ticks if this is what you want.
      Can yo type in the proper steps to be followed in the strategy builder?

      Thanks!

      Comment


        #63
        Hello maaxk,

        Add an int variable on the Inputs and variables page.

        In the condition set where CurrentSeriesHigh is set to the High, also set this variable to the High with the offset type set to ticks and the value set to -20.

        In a new condition set in the Actions select Order management > Enter long position with a limit order, set the Limit price to Misc > name of variable. (The variable will be holding the price of the current high minus 20 ticks.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #64
          Hello Chelsea,

          In what order if you can please guide as per the below instructions you already provided:
          In the Strategy Builder add a double custom series to track the current saved high and use the offset to do math.
          In the first condition set, set the current high series to the value of the previous bar (to carry it forward). Don't add any conditions to this set.
          In the second condition set, add a condition comparing Misc > Current bar, select Equals as the center comparison operator, on the right select Misc > Numeric value > 1.
          In the actions, select Misc > Set CurrentHighSeries, click 'set' in the CurrentHighSeries field, select Price > High.
          In the third condition set, add a condition comparing the Price > High with bars ago 1, Greater, Price > High with bars ago 2.
          In the same (third) condition set, add another condition comparing Price > High with bars ago 0, Greater, Price > High with bars ago 1​
          In the actions, select Misc > Set CurrentHighSeries, click 'set' in the CurrentHighSeries field, select Price > High.
          In the forth condition set, add a condition comparing the Price > Close, select Less as the center comparison operator, on the right select Misc > Custom Series > CurrentHighSeries, and set the Offset Type to Ticks and use -20 as the Value.
          Add an action, select Order management > Enter long position with a market order​​
          Thanks!

          Comment


            #65
            Hello Chelsea,

            This is a kind reminder.

            Thanks

            Comment


              #66
              Hello Chelsea,

              Any Update ?

              Comment


                #67
                Hello Chelsea,

                Its been a while since you last responded.

                Thanks

                Comment


                  #68
                  Hello maaxk,

                  I've made a short video demonstrating to avoid having to type out the verbose instructions repeatedly.


                  Note, if you are not wanting to learn the tools of the Strategy Builder so that you can create your own scripts based on your custom logic, you may want to consider hiring a professional consultant to create the script on your behalf.

                  You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more!
                  Programming Services - https://ninjatraderecosystem.com/sea...mming-services
                  Educators - https://ninjatraderecosystem.com/sea...ures=education

                  You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third party services for NinjaTrader all pricing and support information will need to be obtained through the consultant.

                  This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.​
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #69
                    Hello Chelsea,

                    Thanks you some much for your continued support. I followed the steps from the video recording that your provided and its giving me the below error:
                    8/30/2024 7:32:50 AM Default Strategy 'APriceDropStrategy': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                    Also i am trying to learn the strategy builder but processing so many parameters and knowledge is a bit too much. I will learn with time and yes i will also like to thank your for suggesting the consultant services.

                    Thanks!

                    Comment


                      #70
                      Hello maaxk,

                      Apologies, I overlooked the Strategy Builder isn't adding the proper CurrentBar check automatically if the Set order is modified. (It does if the conditions are added in the correct order)

                      In Set 1, add to the conditions Misc > Current bar, Greater, Misc > Numeric value (set to 0).
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #71
                        Hi Chelsea,

                        I wanted to update you on the recent modifications I made to the strategy. Following your advice, I updated Set 1, and that resolved the initial bug. However, I encountered another issue: the strategy wasn’t entering any long positions when executed.

                        After some adjustments, I removed Set 4, and the strategy began functioning as expected. However, this led to a new problem where the strategy was entering multiple long positions due to frequent stop fills. I attempted to modify the parameters in Set 4 to address this, but it seems that with Set 4 in place, the strategy still does not enter any long positions.

                        Removed Set 4:
                        // Set 4 if ((SystemPerformance.AllTrades.TradesPerformance.Cu rrency.CumProfit != 0) && (Position.MarketPosition == MarketPosition.Flat)) { LimitPrice = 0; }
                        Additionally, after a loss is filled, I need the strategy to wait for the price to rise again, similar to the initial condition, before entering a long position if the conditions are met.

                        Please see the video recording and it will give you a clearer demonstration of what is happening: What it should do: 0:50 onwards, what it shouldn't do: 02:20 onwards.
                        Could you please take a look and advise on how we might resolve these issues? Any suggestions on refining the logic to prevent excessive position entries while ensuring it places long orders correctly would be greatly appreciated.

                        Thank you!

                        Comment


                          #72
                          Hello maaxk,

                          What is the specific logic you want to implement for the behavior you wanting?

                          Again, please do not use general terms (like 'peak') but actual pseudo logic with specific values.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #73
                            Hello Chelsea,

                            NO addition is required just an issue that we need to address. The whole program works perfectly there's just one situation that it is entering a long position once a stop loss is filled. We need to avoid that. Let me explain: Pseudocode for the Current Behavior

                            1. Initialization and Setup:
                              IF State is State.DataLoaded THEN Initialize CustomeHighSeries as a new Series of doubles Set ProfitTarget to 12 ticks Set StopLoss to 20 ticks
                            2. Update Custom High Series:
                              IF CurrentBars[0] > 0 THEN CustomeHighSeries[0] = CustomeHighSeries[1]
                            3. Initialize Custom High Series:
                              IF CurrentBars[0] == 1 THEN CustomeHighSeries[0] = High[0]
                            4. Set Custom High and Limit Price:
                              IF (High[0] > High[1]) AND (High[1] > High[2]) THEN CustomeHighSeries[0] = High[0] Set LimitPrice to CustomeHighSeries[0] - (20 * TickSize)
                            5. Place a Limit Order:
                              IF LimitPrice > 0 THEN EnterLongLimit(2, LimitPrice, "")
                            6. Handling Profit Target and Stop Loss:
                              // When the position hits the profit target IF ProfitTarget is hit THEN Close position normally
                              // When the position hits the stop loss IF StopLoss is hit THEN Re-enter long position at current price (which is lower) This should not happen, i dont know why this is happening.
                            Issue Description

                            The problem occurs when the stop loss is triggered. Instead of handling the stop loss properly, the strategy seems to re-enter a long position at a lower price, which is not the intended behavior.
                            How it should be,
                            1. Initialization and Setup:
                              IF State is State.DataLoaded THEN Initialize CustomeHighSeries as a new Series of doubles Set ProfitTarget to 12 ticks Set StopLoss to 20 ticks
                            2. Update Custom High Series:
                              IF CurrentBars[0] > 0 THEN CustomeHighSeries[0] = CustomeHighSeries[1]
                            3. Initialize Custom High Series:
                              IF CurrentBars[0] == 1 THEN CustomeHighSeries[0] = High[0]
                            4. Set Custom High and Limit Price:
                              IF (High[0] > High[1]) AND (High[1] > High[2]) THEN CustomeHighSeries[0] = High[0] Set LimitPrice to CustomeHighSeries[0] - (20 * TickSize)
                            5. Place a Limit Order:
                              IF LimitPrice > 0 THEN EnterLongLimit(2, LimitPrice, "")
                            6. Handling Profit Target and Stop Loss:
                              // When the position hits the profit target IF ProfitTarget is hit THEN Close position normally
                              // When the position hits the stop loss IF StopLoss is hit THEN close position normally and not reenter again.


                              For your reference i am again pasting the link to to the video recording:
                            ​Please see the video recording and it will give you a clearer demonstration of what is happening: What it should do: 0:50 onwards, what it shouldn't do: 02:20 onwards.
                            https://drive.google.com/file/d/1Hgs...ew?usp=sharing


                            Please let me know how we can correct it.

                            Thanks!

                            Comment


                              #74
                              Hello Chelsea,

                              Here's a more clear explanation:

                              • Initialization:
                                • Set up CustomeHighSeries to track the highest price.
                                • Initialize LimitPrice and isNewHigh to manage order placement.
                              • Update Custom High Series:
                                • Update CustomeHighSeries to the previous value if there are more than 0 bars.
                              • Initialize Custom High Series:
                                • When there is exactly 1 bar, set the initial high.
                              • Check for New High and Set Limit Price:
                                • If the current high is higher than the previous highs, update CustomeHighSeries and calculate the LimitPrice. Set isNewHigh to true.
                              • Check for Downward Price Movement:
                                • If the current closing price is lower than the previous closing price, reset isNewHigh to false to prevent order placement.
                              • Place a Limit Order:
                                • Place a long limit order only if isNewHigh is true and LimitPrice is valid.
                              Only enter a long position of the the current bar has closed higher than the previous. if it has closed lower than the previous one then don't enter a long position.

                              Comment


                                #75
                                Hello Chelsea,

                                This is a kind reminder.

                                Thanks

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                648 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                369 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                108 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                572 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                573 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X