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

    #16
    Hello maaxk,

    Interesting, the Strategy Builder should have automatically added the check for CurrentBar before Set 1. I'll need to report this to our development.
    May I confirm you are using 8.1.3.1 and not an out of date release of NinjaTrader Desktop?

    May I confirm you are still building this with the Strategy Builder?

    To correct the error, add a condition to Set 1.
    On the left select Misc > Current bar, Greater in the center operator, on the right select Misc > Numeric value (leave this set to 0).
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hello Chelsea,

      Yes i am using the latest version 8.1.3.1 of the ninja trader desktop application, and yes, i am still building this with the strategy builder.

      Okay ill make the amendment to the set 1 and let you know of the outcome.

      Thanks!

      Comment


        #18
        Hello Chelsea,

        I did that exactly and the disabling issue is resolved, however its still not entering any long position. How can we make that possible?

        Thanks!

        Comment


          #19
          Hello maaxk,

          I've given this a test on the ES 09-24 and I am finding a few orders were submitted.
          I also added debugging prints to show on what bars the condition will be true.

          Attached is the test script and the output saved from the output window.
          DropFromPrevoiusHighTest_NT8.zip
          NinjaScript Output 8_22_2024 10_00 AM.txt

          The strategy starts with assigning the high of the 2nd bar on the chart as a starting high.

          If the market price (Close) is less than the high of that bar then an order is submitted and the bar of the submission is saved as the new current high.

          Is this is the logic you are wanting?
          If not, what is the specific logic you want to save a new high?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hello Chelsea,

            Can you try it on NQ Sep24

            Thanks!

            Comment


              #21
              Hello maaxk,

              I've added this on a NQ 09-24 1 minute chart and several orders were placed.
              Attached Files
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hello Chelsea,

                I see its working with you.

                Can you please check my code again and compare it wit yours?

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

                private Series<double> currenthighseries;

                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"enter a long position after a previous high";
                Name = "prevhilongpos11p";
                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)
                {
                AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }
                else if (State == State.DataLoaded)
                {
                currenthighseries = new Series<double>(this);
                SetProfitTarget(CalculationMode.Ticks, 30);
                SetStopLoss(CalculationMode.Ticks, 20);
                }
                }

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

                if (CurrentBars[0] < 1)
                return;

                // Set 1
                if (CurrentBars[0] > 0)
                {
                currenthighseries[0] = currenthighseries[1];
                }

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

                // Set 3
                if (Close[0] < (currenthighseries[0] + (-20 * TickSize)) )
                {
                EnterLong(2, "");
                currenthighseries[0] = High[0];
                }

                }
                }
                }​
                Thanks!

                Comment


                  #23
                  Hello maaxk,

                  In Set 2 I have CurrentBars == 1 (Misc > Current bar, Equals, 1) to save the high of the first bar as the starting point.

                  Add debugging prints and enable TraceOrders (on the Defaults) page if you want to know why your strategy is not submitting orders.

                  Below is a link to a support article on adding debugging prints understand behavior.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hello Chelsea,

                    There are some limitations to the strategy builder, I dont know how to do that in the strategy builder. i tried current bars == 1 but there's no option.

                    Thanks!

                    Comment


                      #25
                      Hello maaxk,

                      On the left select Misc > Current bar, Equals in the center operator, on the right select Misc > Numeric value, set the value to 1.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        I updated the code now and shifted from builder to code:

                        #region Using declarations
                        using System;
                        using System.Collections.Generic;
                        using System.ComponentModel;
                        using System.ComponentModel.DataAnnotations;
                        using System.Linq;
                        using System.Text;
                        using System.Threading.Tasks;
                        using System.Windows;
                        using System.Windows.Input;
                        using System.Windows.Media;
                        using System.Xml.Serialization;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Gui;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Gui.SuperDom;
                        using NinjaTrader.Gui.Tools;
                        using NinjaTrader.Data;
                        using NinjaTrader.NinjaScript;
                        using NinjaTrader.Core.FloatingPoint;
                        using NinjaTrader.NinjaScript.Indicators;
                        using NinjaTrader.NinjaScript.DrawingTools;
                        #endregion

                        //This namespace holds Strategies in this folder and is required. Do not change it.
                        namespace NinjaTrader.NinjaScript.Strategies
                        {
                        public class prevhilongpos11p : Strategy
                        {

                        private Series<double> currenthighseries;

                        protected override void OnStateChange()
                        {
                        if (State == State.SetDefaults)
                        {
                        Description = @"enter a long position after a previous high";
                        Name = "prevhilongpos11p";
                        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)
                        {
                        AddDataSeries(Data.BarsPeriodType.Tick, 1);
                        }
                        else if (State == State.DataLoaded)
                        {
                        currenthighseries = new Series<double>(this);
                        SetProfitTarget(CalculationMode.Ticks, 30);
                        SetStopLoss(CalculationMode.Ticks, 20);
                        }
                        }

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

                        if (CurrentBars[0] < 1)
                        return;

                        // Set 1
                        if (CurrentBars[1] > 1)
                        {
                        currenthighseries[0] = currenthighseries[1];
                        }

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

                        // Set 3
                        if (Close[0] < (currenthighseries[0] + (-20 * TickSize)) )
                        {
                        EnterLong(2, "");
                        currenthighseries[0] = High[0];

                        }

                        }
                        }
                        }
                        Please compare with your code and let me know.

                        Thanks!

                        Comment


                          #27
                          Hello maaxk,

                          Have look at the script I have provided you.
                          In Set 2 I have Misc > Custom series > CurrentHighSeries, Equals as the comparison operator, and Numeric value 1 on the right.
                          For the action Misc > Set CurrentHighSeries with the value set to Price > High with Bars ago 0.
                          Your suggested code has Misc > Custom series > CurrentHighSeries, Greater as the comparison operator, and Price > High on the right.
                          For the action Misc > Set CurrentHighSeries with the value set to Price > High with Bars ago 1.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #28
                            I copied your exact code:
                            #region Using declarations
                            using System;
                            using System.Collections.Generic;
                            using System.ComponentModel;
                            using System.ComponentModel.DataAnnotations;
                            using System.Linq;
                            using System.Text;
                            using System.Threading.Tasks;
                            using System.Windows;
                            using System.Windows.Input;
                            using System.Windows.Media;
                            using System.Xml.Serialization;
                            using NinjaTrader.Cbi;
                            using NinjaTrader.Gui;
                            using NinjaTrader.Gui.Chart;
                            using NinjaTrader.Gui.SuperDom;
                            using NinjaTrader.Gui.Tools;
                            using NinjaTrader.Data;
                            using NinjaTrader.NinjaScript;
                            using NinjaTrader.Core.FloatingPoint;
                            using NinjaTrader.NinjaScript.Indicators;
                            using NinjaTrader.NinjaScript.DrawingTools;
                            #endregion

                            //This namespace holds Strategies in this folder and is required. Do not change it.
                            namespace NinjaTrader.NinjaScript.Strategies
                            {
                            public class DropFromPrevoiusHighTest : Strategy
                            {

                            private Series<double> CurrentHighSeries;

                            protected override void OnStateChange()
                            {
                            if (State == State.SetDefaults)
                            {
                            Description = @"";
                            Name = "DropFromPrevoiusHighTest";
                            Calculate = Calculate.OnBarClose;
                            EntriesPerDirection = 999;
                            EntryHandling = EntryHandling.AllEntries;
                            IsExitOnSessionCloseStrategy = true;
                            ExitOnSessionCloseSeconds = 30;
                            IsFillLimitOnTouch = false;
                            MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                            OrderFillResolution = OrderFillResolution.Standard;
                            Slippage = 0;
                            StartBehavior = StartBehavior.WaitUntilFlat;
                            TimeInForce = TimeInForce.Gtc;
                            TraceOrders = true;
                            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);
                            }
                            }

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

                            if (CurrentBars[0] < 1)
                            return;

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

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

                            // Set 3
                            if (Close[0] < (CurrentHighSeries[0] + (-20 * TickSize)) )
                            {
                            CurrentHighSeries[0] = High[0];
                            EnterLong(2, "");
                            Draw.Dot(this, @"DropFromPrevoiusHighTest Dot_1 " + Convert.ToString(CurrentBars[0]), true, 0, (High[0] + (3 * TickSize)) , Brushes.CornflowerBlue);
                            }

                            }
                            }
                            }​
                            Saved it and run it, and its still not showing me any historical orders, i am working on it on a chart i already provided.

                            Thanks!

                            Comment


                              #29
                              Hello maaxk,

                              May I have the output from the debugging prints to understand why the condition is not evaluating as true?
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                Where will i get the debugging prints?

                                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