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

    #46
    Hello maaxk,

    I see you have notes added in the screenshot, but I am not seeing any rules of logic.

    Where you have 1, what are the specific rules that makes this a peak arrow head?

    Where you have 3, what are the specific rules that it would enter a long position?

    Where you have 4, you want to define the new current high as being 2 points higher than the previous current high?

    Where you have 5, looking in reverse in the Strategy Builder means checking the specific bars ago. You wont be able to use loops in the Strategy Builder. How many bars specifically do you want to look back? (It would be better to just have the data updated at that point instead of looking back..)

    Where you have 6, what are the rules that would enter a second long position.

    Try writing this logic out in words as this may help you to define the specific logic.

    You need to be using specific bar numbers and high / low / close values in your pseudo logic, not generalized ideas.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #47
      Hello Chelsea:
      Specific Rules and Pseudo Logic

      1. Identifying a Peak (Arrowhead)
      • Rule for Peak: A peak is identified when the high of the current bar is higher than the highs of the preceding and succeeding bars.
      • Logic:
        • Compare the high of the current bar (Bar X) with the highs of the previous bar (Bar X-1) and the next bar (Bar X+1).
        • Condition: If High[Bar X] > High[Bar X-1] and High[Bar X] > High[Bar X+1], then Bar X is identified as a peak.
      2. Entry Condition for Long Position
      • Rule for Entry: Enter a long position when the price drops by a specified number of ticks (e.g., 20 ticks, 30 ticks) from the peak.
      • Logic:
        • After identifying the peak (previous high), monitor the price for a drop.
        • Condition: If the price falls by 20 ticks (or another chosen number) from the peak price, then enter a long position.
        • Example: If the peak price was $2000, then enter a long position when the price drops to $1980 (assuming a 20-tick drop).
      3. Setting a New High
      • Rule for New High: A new high is identified if a new bar’s high exceeds the current high.
      • Logic:
        • Compare the high of the current bar with the high of the previous bar.
        • Condition: If the high of the current bar (Bar Y) is greater than the high of the previous high (Bar X), then update the current high to the high of Bar Y.
      4. Handling Bars in Strategy Builder
      • Bar Lookback: Since loops cannot be used, focus on direct bar comparisons.
      • Logic:
        • Only compare each bar’s high to the preceding bar’s high.
        • Condition: Set the current high based on whether the current bar’s high exceeds the previous bar’s high. Do not use a lookback beyond the immediate previous bar.
      5. Entering a Second Long Position
      • Rule for Second Entry: Similar to the first entry, identify a new peak and enter a second long position if the price drops by the specified number of ticks from this new peak.
      • Logic:
        • Once a new high is identified, monitor for a price drop.
        • Condition: If the price drops by 20 ticks (or another specified number) from the new high, then enter another long position.
      1. Identify Peak (Arrowhead):
      For each bar (Bar X):
      If High[Bar X] > High[Bar X-1] and High[Bar X] > High[Bar X+1]:
      Set Peak = High[Bar X]
      Store Peak as previousHigh

      2. Enter Long Position:
      If current price <= previousHigh - 20 ticks (or chosen number):
      Enter long position

      3. Update to New High:
      For each new bar (Bar Y):
      If High[Bar Y] > previousHigh:
      Set previousHigh = High[Bar Y]

      4. Enter Second Long Position:
      After closing the first trade:
      If current price <= previousHigh - 20 ticks (or chosen number):
      Enter second long position
      Summary
      • Peak Identification: Determine peaks by comparing each bar’s high to the neighboring bars.
      • Entry Condition: Enter a long position when the price drops by a defined number of ticks from the identified peak.
      • New High: Update the high when a new bar’s high exceeds the previous high.
      • No Loops: Directly compare each bar’s high to the preceding bar’s high, without using lookback loops.
      • Second Entry: Apply the same logic as the first entry for any subsequent trades.
      ​This is what is can do at most.

      Thanks!

      Comment


        #48
        Hello maaxk,

        "Compare the high of the current bar (Bar X) with the highs of the previous bar (Bar X-1) and the next bar (Bar X+1)"

        The next bar hasn't happened when the current bar is updating. You would have to wait for that bar to open.

        Price > High, bars ago 1, Greater, Price > High bars ago 2
        Price > High, bars ago 0, Greater, Price > High bars ago 1

        "If the price falls by 20 ticks (or another chosen number) from the peak price, then enter a long position."

        Price > Close, Less, Misc > Custom series > CurrentHighSeries - 20 * TickSize

        "Compare the high of the current bar with the high of the previous bar."

        Price > High, bars ago 0, Greater, Price > High bars ago 1

        "Only compare each bar’s high to the preceding bar’s high."

        Price > High, bars ago 0, Greater, Price > High bars ago 1

        "Similar to the first entry, identify a new peak and enter a second long position if the price drops by the specified number of ticks from this new peak."

        Price > Close, Less, Misc > Custom series > CurrentHighSeries - 20 * TickSize
        Chelsea B.NinjaTrader Customer Service

        Comment


          #49
          Hello Chelsea,

          Would you please guide me step wise, how many sets, and which condition in which set just like the previous strategy ?

          Thanks!

          Comment


            #50
            Hello maaxk,

            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​
            Chelsea B.NinjaTrader Customer Service

            Comment


              #51
              Hi Chelsea,

              I followed your instructions from the last response, but I'm encountering an issue with the entry into the long position. It seems to be entering at -30 ticks, regardless of the condition I set.

              For instance, I set the condition to -20 ticks as expected, but it enters at -30 ticks. I also tried various tick numbers like -24, -26, -28, and -30, but the entry still occurs after -30 ticks. When I set numbers greater than -30 (e.g., -36, -38, -40), it doesn’t enter the long position at all.

              My point is that the system should allow entry when any desired number is set in the condition, whether it’s -20, -25, -35, etc.

              I’ve attached my source code for your reference.

              namespace NinjaTrader.NinjaScript.Strategies
              {
              public class Buyafterdrop : Strategy
              {

              private Series<double> CurrentHighSeries;

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Strategy here.";
              Name = "Buyafterdrop";
              Calculate = Calculate.OnBarClose;
              EntriesPerDirection = 1;
              EntryHandling = EntryHandling.AllEntries;
              IsExitOnSessionCloseStrategy = true;
              ExitOnSessionCloseSeconds = 30;
              IsFillLimitOnTouch = false;
              MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
              OrderFillResolution = OrderFillResolution.Standard;
              Slippage = 0;
              StartBehavior = StartBehavior.WaitUntilFlat;
              TimeInForce = TimeInForce.Gtc;
              TraceOrders = false;
              RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
              StopTargetHandling = StopTargetHandling.PerEntryExecution;
              BarsRequiredToTrade = 20;
              // Disable this property for performance gains in Strategy Analyzer optimizations
              // See the Help Guide for additional information
              IsInstantiatedOnEachOptimizationIteration = true;
              }
              else if (State == State.Configure)
              {
              }
              else if (State == State.DataLoaded)
              {
              CurrentHighSeries = new Series<double>(this);
              SetProfitTarget(CalculationMode.Ticks, 28);
              SetStopLoss(CalculationMode.Ticks, 40);
              }
              }

              protected override void OnBarUpdate()
              {
              if (BarsInProgress != 0)
              return;

              if (CurrentBars[0] < 2)
              return;

              CurrentHighSeries[1] = 0;
              // Set 2
              if (CurrentBars[0] == 1)
              {
              CurrentHighSeries[0] = High[0];
              }

              // Set 3
              if ((High[1] > High[2])
              && (High[0] > High[1]))
              {
              CurrentHighSeries[0] = High[0];
              }

              // Set 4
              if (Close[0] < (CurrentHighSeries[0] + (-20 * TickSize)) )
              {
              EnterLong(2, "");
              }

              }
              }
              }​
              Could you please advise on what might be going wrong and how to fix it?

              Thank you!

              Comment


                #52
                Hello maaxk,

                When using Calculate.OnBarClose a market order will fill at the open of the next bar.

                If you want the order to fill at a specific price (or better) use a limit order.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #53
                  Hello Chelsea,

                  Can you please guide me on how to put a limit order?

                  Also what about:
                  It seems to be entering at -30 ticks, regardless of the condition I set.

                  For instance, I set the condition to -20 ticks as expected, but it enters at -30 ticks. I also tried various tick numbers like -24, -26, -28, and -30, but the entry still occurs after -30 ticks. When I set numbers greater than -30 (e.g., -36, -38, -40), it doesn’t enter the long position at all.​
                  Thanks!

                  Comment


                    #54
                    Hello maaxk,

                    In the Actions window select Order management > Enter long position with a limit order.

                    Note, if the order is not filled on the submission bar it will automatically be cancelled unless the order is resubmitted on the next bar.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #55
                      Hello Chelsea,

                      Please let me know properly how to set up this limit order as i have done it and its not entering any long position:

                      Please see the screenshot for reference:

                      Click image for larger version

Name:	image.png
Views:	122
Size:	65.2 KB
ID:	1316043

                      Please let me know what to put in the limit price field.

                      Thanks​

                      Comment


                        #56
                        Hello maaxk,

                        To confirm, are you familiar with all of the order types and how they work?

                        If not, I would recommend learning about these first. Investopedia is a helpful website that provides descriptions of order types and other trading terms.


                        The limit price is the price the order will be submitted at.

                        When you say 'Please let me know what to put in the limit price field.' this would be the price you want to submit the order at.

                        What price do you want to submit the order at?

                        Do you want to place the order at the current market price minus 20 ticks?
                        If so, select Price > Close and set the Offset Type to Ticks and set the Value to -20.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #57
                          Hello Chelsea,

                          Then What about this condition:
                          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.
                          Isn't it conflicting?

                          Also i did as you aid but now it submits the order and then cancels it not setting or hitting the profit target or stop loss.

                          Any thoughts?

                          Thanks!

                          Comment


                            #58
                            Hello Chelsea, In reference to my previous response:
                            Click image for larger version

Name:	image.png
Views:	119
Size:	72.0 KB
ID:	1316059
                            Thanks!​

                            Comment


                              #59
                              Hello maaxk,

                              The condition is true if the current market price is less than the current saved high minus 20 ticks. This could be 50 ticks below or 100 ticks below, etc. The order would fill at whatever the market price is when the bar closes and the order is submitted.

                              If you want to submit an order at a specific price you would need to know what price you want to submit the order at.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #60
                                Hello Chelsea,

                                I don't what to enter when the bar closes, i want to enter when it drops by 20 ticks to be exact after the highest point.
                                But now instead it enters the long position and cancels the orders instantly.

                                I think its clear from the very beginning.

                                Comment

                                Latest Posts

                                Collapse

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