Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modify the PriorDayOHLC Indicator

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

    Modify the PriorDayOHLC Indicator

    Hello Traders,

    I made a copy from the NT8 Indicator "PriorDayOHLC" and reduced its a bit for own experiences for working only with the prior high and low.

    Now I want to add two rectangle objects.
    This both rectangles should be drawn in the current day starting from the prior day high and low.

    For example:
    if the range (100 percent) between the prior days high (10.200) and low (10.000) is 200 points:
    - the upper rectangle should be drawn between 10.160 and 10.200 (40 points = 20 percent of the range
    - the lower rectangle should be drawn between 10.000 and 10.040 (40 points = 20 percent of the range

    Start is the current day and the end is the current bar.
    Both rectangles with a part-transparence field and borders.


    I found this code in the NT8 Help:
    Draw.Rectangle(this,"tag1",false,10,Low[10]-TickSize,5,High[5]+TickSize,Brushes.PaleGreen,Brushes.PaleGreen,2);

    But each position, I tried to use this example, was failing.
    Is there a problem with the "AddPlot"-method in the original indicator?

    Can one of you build me an working example?
    Or giving me a fully step-by-step-instruction, so that I can solve the problem?


    Thank you!

    Best regards,
    Rainbowtrader
    Last edited by Rainbowtrader; 11-03-2021, 10:35 AM.

    #2
    Hello Rainbowtrader,

    Thanks for your post.

    This is a bit complex to provide a small example without writing the full script, but we can provide some direction to help you attain your goal, and answer questions along the way.

    A rectangle will need to have a start and end point. The Start BarsAgo could be (CurrentBar - BarIndexOfFirstBarOfSession) and the End BarsAgo can be 0 for the current bar. You can save CurrentBar to a private variable when Bars.IsFirstBarOfSession is true for BarIndexOfFirstBarOfSession.

    You can then consider setting the StartY of the rectangle to be the PriorDayOHLC's High + (PriorDayOHLC's High - PriorDayOHLC's Low) * .20. This will set the upper bound of the rectangle to be above the prior day high by 20% of the prior day's range.

    You can then consider setting the EndY of the rectangle to be the PriorDayOHLC's Low - (PriorDayOHLC's High - PriorDayOHLC's Low) * .20. This will set the lower bound of the rectangle to be below the prior day low by 20% of the prior day's range.

    As you are testing, be sure to use prints to check your math, so you know the rectangle is being given the values you expect.

    Print - https://ninjatrader.com/support/help.../nt8/print.htm

    Also note that since you require at least 1 session to be calculated to properly draw the rectangle, I suggest incrementing a private integer each time you see a new session (when Bars.IsFirstBarOfSession is true) and only draw your rectangle when that integer is greater than 1.

    Draw.Rectangle documentation - https://ninjatrader.com/support/help..._rectangle.htm


    Comment


      #3
      Hello Jim,

      thank you for the explainings.
      I am giving you here the code, so that is better for me


      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.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion
      
      // This namespace holds indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
      /// <summary>
      /// Zeigt Vortageshoch und-Tief an
      /// </summary>
      public class DifferentZones : Indicator
      {
      private DateTime currentDate = Core.Globals.MinDate;
      private double currentHigh = 0;
      private double currentLow = 0;
      private double currentOpen = 0;
      private double priorDayHigh = 0;
      private double priorDayLow = 0;
      private double priorDayOpen = 0;
      private Data.SessionIterator sessionIterator;
      
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "Different Zones in my Trading";
      Name = "DifferentZones";
      IsAutoScale = false;
      IsOverlay = true;
      IsSuspendedWhileInactive = true;
      DrawOnPricePanel = false;
      ShowLow = true;
      ShowHigh = true;
      
      AddPlot(new Stroke(Brushes.Silver, 10), PlotStyle.HLine, NinjaTrader.Custom.Resource.PriorDayOHLCHigh);
      AddPlot(new Stroke(Brushes.Silver, 10), PlotStyle.HLine, NinjaTrader.Custom.Resource.PriorDayOHLCLow);
      }
      else if (State == State.Configure)
      {
      currentDate = Core.Globals.MinDate;
      currentHigh = 0;
      currentLow = 0;
      priorDayHigh = 0;
      priorDayLow = 0;
      sessionIterator = null;
      }
      else if (State == State.DataLoaded)
      {
      sessionIterator = new Data.SessionIterator(Bars);
      }
      else if (State == State.Historical)
      {
      if (!Bars.BarsType.IsIntraday)
      {
      Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PriorDayOHLCIntradayEr ror, TextPosition.BottomRight);
      Log(NinjaTrader.Custom.Resource.PriorDayOHLCIntrad ayError, LogLevel.Error);
      }
      }
      }
      
      protected override void OnBarUpdate()
      {
      if (!Bars.BarsType.IsIntraday)
      return;
      
      // If the current data is not the same date as the current bar then its a new session
      if (currentDate != sessionIterator.GetTradingDay(Time[0]) || currentOpen == 0)
      {
      // The current day OHLC values are now the prior days value so set
      // them to their respect indicator series for plotting
      priorDayHigh = currentHigh;
      priorDayLow = currentLow;
      
      if (ShowHigh) PriorHigh[0] = priorDayHigh;
      if (ShowLow) PriorLow[0] = priorDayLow;
      
      // Initilize the current day settings to the new days data
      currentOpen = Open[0];
      currentHigh = High[0];
      currentLow = Low[0];
      
      currentDate = sessionIterator.GetTradingDay(Time[0]);
      }
      else // The current day is the same day
      {
      // Set the current day OHLC values
      currentHigh = Math.Max(currentHigh, High[0]);
      currentLow = Math.Min(currentLow, Low[0]);
      
      if (ShowHigh) PriorHigh[0] = priorDayHigh;
      if (ShowLow) PriorLow[0] = priorDayLow;
      }
      }
      
      #region Properties
      [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
      [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
      public Series<double> PriorHigh
      {
      get { return Values[0]; }
      }
      
      [Browsable(false)]
      [XmlIgnore()]
      public Series<double> PriorLow
      {
      get { return Values[1]; }
      }
      
      [Display(ResourceType = typeof(Custom.Resource), Name = "ShowHigh", GroupName = "Rainbowtrader", Order = 0)]
      public bool ShowHigh
      { get; set; }
      
      [Display(ResourceType = typeof(Custom.Resource), Name = "ShowLow", GroupName = "Rainbowtrader", Order = 1)]
      public bool ShowLow
      { get; set; }
      
      #endregion
      }
      }
      Last edited by Rainbowtrader; 11-03-2021, 11:55 AM.

      Comment


        #4
        Hello Jim,

        it is possible for you to write the examples in this code or is this code too overloaded for this? I had found this here. It is better for starting this project, or?

        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.DrawingTools;
        #endregion
        
        namespace NinjaTrader.NinjaScript.Indicators
        {
        /// <summary>
        /// Description
        /// </summary>
        public class RectangleExample : Indicator
        {
        private bool DoItOnce = true, keepDrawing = true;
        private int startBar;
        private double rect_high, rect_low;
        
        //---------------------------------------------------------------------------------------------------------------------------
        protected override void OnStateChange()
        //---------------------------------------------------------------------------------------------------------------------------
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Indicator here.";
        Name = "RectangleExample";
        Calculate = Calculate.OnEachTick;
        IsOverlay = true;
        DisplayInDataBox = true;
        DrawOnPricePanel = true;
        PaintPriceMarkers = false;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        IsSuspendedWhileInactive = true;
        }
        else if (State == State.Configure)
        {
        }
        }
        
        //---------------------------------------------------------------------------------------------------------------------------
        protected override void OnBarUpdate()
        //---------------------------------------------------------------------------------------------------------------------------
        {
        if (State != State.Realtime) return;
        
        if (DoItOnce)
        {
        startBar = CurrentBar - 30;
        rect_high = High[30];
        rect_low = Low[30];
        Draw.Rectangle(this, "Rechteck1", (CurrentBar - startBar), rect_high, 0, rect_low, Brushes.DodgerBlue, true);
        
        DoItOnce = false;
        }
        else if (keepDrawing)
        {
        Draw.Rectangle(this, "Rechteck1", (CurrentBar - startBar), rect_high, 0, rect_low, Brushes.DodgerBlue, true);
        }
        
        if (CrossAbove(High, rect_low, 1) || CrossBelow(Low, rect_high, 1))
        keepDrawing = false;
        
        }
        }
        }
        Thank you,
        Rainbowtrader

        Comment


          #5
          Hello Rainbowtrader,

          We really want you to try making the changes, and we can support you by answering questions along the way. If understanding how to write the NinjaScript/C# syntax is difficult, using the Strategy Builder to draw some simple rectangles and clicking the View Code button can help to better understand how to work with the code.

          Drawing on a chart from Strategy Builder - https://ninjatrader.com/support/help...ToDrawOnAChart

          I suggest starting there to get the syntax down for drawing rectangles. Please also refer to the Draw.Rectangle documentation and Intelliprompt to get more familiar using other overloads.

          Intelliprompt - https://ninjatrader.com/support/help...elliprompt.htm

          You could then consider making a copy of your work from post #2 to make your changes. Instead of using Bars.IsFirstBarOfSession, you could use the existing condition if (currentDate != sessionIterator.GetTradingDay(Time[0]) || currentOpen == 0) to set the bar index for your private integer BarIndexOfFirstBarOfSession.

          I.E.

          BarIndexOfFirstBarOfSession = CurrentBar;

          Then you just need to draw your rectangle. You can consider drawing this when you assign the PriorHigh and PriorLow plots.

          This could look like the following:

          Draw.Rectangle(this, "tag", (CurrentBar - BarIndexOfFirstBarOfSession), priorDayHigh + (priorDayHigh - priorDayLow) * .20, 0, priorDayLow - (priorDayHigh - priorDayLow) *.20, Brushes.Blue);

          Comment


            #6
            Hello Jim,

            thanks a lt for you help!

            I am thinking, that I made the things like you had written.
            My indicator works, but not so like I am wishing.

            Now in the next step I am wishing 3 things to optimize, and I need your help again for this:
            1. The rectangles are starting with the first bar in the new session. I would love, that the rectangles are starting "one bar" (the space between the daily break and the first bar) earlier at the beginning of the new session.
            2. I cant reducing the thickness of the borders/lines. I am wishing its to reduce to one pixel instead the 2 or 3 pixel the borders/lines are. I had found no solution for my code.
            3. Whatever I tried in using the variables: I could not find a solution, that the rectangles are stopping at the current bar (like the both silver prior day high and low lines). So I had set the lenght og the rectangles in my example by define its to "-100".
            Here is the code from my indicator:

            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
            
            namespace NinjaTrader.NinjaScript.Indicators
            {
            /// <summary>
            /// Handelszonen
            /// </summary>
            public class Handelszonen : Indicator
            {
            private DateTime currentDate = Core.Globals.MinDate;
            private double currentHigh = 0;
            private double currentLow = 0;
            private double currentOpen = 0;
            private double priorDayHigh = 0;
            private double priorDayLow = 0;
            private double priorDayOpen = 0;
            private Data.SessionIterator sessionIterator;
            private int BarIndexOfFirstBarOfSession;
            
            //---------------------------------------------------------------------------------------------------------------------------
            protected override void OnStateChange()
            //---------------------------------------------------------------------------------------------------------------------------
            {
            if (State == State.SetDefaults)
            {
            Description = "Handelszonen";
            Name = "Handelszonen";
            IsAutoScale = false;
            IsOverlay = true;
            IsSuspendedWhileInactive = true;
            DrawOnPricePanel = false;
            ShowLow = true;
            ShowHigh = true;
            PaintPriceMarkers = false;
            
            AddPlot(new Stroke(Brushes.Silver, 10), PlotStyle.HLine, NinjaTrader.Custom.Resource.PriorDayOHLCHigh);
            AddPlot(new Stroke(Brushes.Silver, 10), PlotStyle.HLine, NinjaTrader.Custom.Resource.PriorDayOHLCLow);
            }
            else if (State == State.Configure)
            {
            currentDate = Core.Globals.MinDate;
            currentHigh = 0;
            currentLow = 0;
            priorDayHigh = 0;
            priorDayLow = 0;
            sessionIterator = null;
            }
            else if (State == State.DataLoaded)
            {
            sessionIterator = new Data.SessionIterator(Bars);
            }
            else if (State == State.Historical)
            {
            if (!Bars.BarsType.IsIntraday)
            {
            Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PriorDayOHLCIntradayEr ror, TextPosition.BottomRight);
            Log(NinjaTrader.Custom.Resource.PriorDayOHLCIntrad ayError, LogLevel.Error);
            }
            }
            }
            
            
            //---------------------------------------------------------------------------------------------------------------------------
            protected override void OnBarUpdate()
            //---------------------------------------------------------------------------------------------------------------------------
            {
            if (!Bars.BarsType.IsIntraday)
            return;
            
            if (currentDate != sessionIterator.GetTradingDay(Time[0]) || currentOpen == 0)
            {
            priorDayHigh = currentHigh;
            priorDayLow = currentLow;
            
            if (ShowHigh) PriorHigh[0] = priorDayHigh;
            if (ShowLow) PriorLow[0] = priorDayLow;
            
            BarIndexOfFirstBarOfSession = CurrentBar;
            Draw.Rectangle(this, "oben1", false, (CurrentBar - BarIndexOfFirstBarOfSession), priorDayHigh, (-100), priorDayHigh - (priorDayHigh - priorDayLow) * .10, Brushes.DarkGreen, Brushes.DarkGreen, 30);
            Draw.Rectangle(this, "oben2", false, (CurrentBar - BarIndexOfFirstBarOfSession), priorDayHigh - (priorDayHigh - priorDayLow) * .10, (-100), priorDayHigh - (priorDayHigh - priorDayLow) * .20, Brushes.ForestGreen, Brushes.ForestGreen, 20);
            Draw.Rectangle(this, "unten1", false, (CurrentBar - BarIndexOfFirstBarOfSession), priorDayLow, (-100), priorDayLow - (priorDayLow - priorDayHigh) * .10, Brushes.Maroon, Brushes.Maroon, 30);
            Draw.Rectangle(this, "unten2", false, (CurrentBar - BarIndexOfFirstBarOfSession), priorDayLow - (priorDayLow - priorDayHigh) * .10, (-100), priorDayLow - (priorDayLow - priorDayHigh) * .20, Brushes.Red, Brushes.Red, 20);
            
            currentOpen = Open[0];
            currentHigh = High[0];
            currentLow = Low[0];
            
            currentDate = sessionIterator.GetTradingDay(Time[0]);
            }
            else
            {
            currentHigh = Math.Max(currentHigh, High[0]);
            currentLow = Math.Min(currentLow, Low[0]);
            
            if (ShowHigh) PriorHigh[0] = priorDayHigh;
            if (ShowLow) PriorLow[0] = priorDayLow;
            }
            }
            
            #region Properties
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> PriorHigh
            {
            get { return Values[0]; }
            }
            
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> PriorLow
            {
            get { return Values[1]; }
            }
            
            [Display(ResourceType = typeof(Custom.Resource), Name = "ShowHigh", GroupName = "Handelszonen", Order = 0)]
            public bool ShowHigh
            { get; set; }
            
            [Display(ResourceType = typeof(Custom.Resource), Name = "ShowLow", GroupName = "Handelszonen", Order = 1)]
            public bool ShowLow
            { get; set; }
            
            #endregion
            }
            }
            Thank you, Jim!

            Best regards,
            Rainbowtrader
            Attached Files

            Comment


              #7
              Hello Rainbowtrader,

              The rectangles are starting with the first bar in the new session. I would love, that the rectangles are starting "one bar" (the space between the daily break and the first bar) earlier at the beginning of the new session.
              You can change the startBarsAgo parameter. If you add 1 to this parameter, the rectangle will start one bar back.

              I cant reducing the thickness of the borders/lines. I am wishing its to reduce to one pixel instead the 2 or 3 pixel the borders/lines are. I had found no solution for my code.
              There is not a parameter for this, but you may change the Width of the rectangle's OutlineStroke if you instantiate the rectangle as Rectangle object.

              I.E.

              myRec.OutlineStroke.Width = 1;

              https://ninjatrader.com/support/help.../rectangle.htm
              Whatever I tried in using the variables: I could not find a solution, that the rectangles are stopping at the current bar (like the both silver prior day high and low lines). So I had set the lenght og the rectangles in my example by define its to "-100".
              Unless you want to get into custom SharpDX rendering, which we really only would recommend for advanced developers, you are left using BarsAgo or bar times to draw the rectangle. I'll include some information below, but you may wish to stick with your current solution if that is easier and works for you.

              To get more acquainted with SharpDX rendering, please see the Help Guide article below, and please see the SampleCustomRender indicator that comes with NinjaTrader.

              https://ninjatrader.com/support/help..._rendering.htm

              Comment


                #8
                Hello Jim,

                thank you for your answers

                1. The start bar:
                This solution does not works. If I am adding +1 in the code...
                Code:
                Draw.Rectangle(this, "oben1",  false, (CurrentBar - BarIndexOfFirstBarOfSession +1), priorDayHigh, (-100), priorDayHigh - (priorDayHigh - priorDayLow)  * .10, Brushes.DarkGreen, Brushes.DarkGreen, 30);
                ...then all 6 drawings are gone in my chart. Its an empty chart then.

                2. The parameter of thickness:
                Yesterday I experimented with this part of code, but I dont know, what exactly is to do, to bring its to work. I failed. The NT8 help pages are showing an example, that looks not like made for my problem. Can you give me more informations to solve this?

                3. Drawing only till the current bar:
                Did I understood its well, that without the "SampleCustomRender" there is no way to solve its?

                Best regards,
                Rainbowtrader

                Comment


                  #9
                  Hello Rainbowtrader,

                  If the indicator disappears, you are likely hitting an error. Please check the log tab of the Control Center for any errors and and make sure they are corrected. Be sure that you are using CurrentBar checks to make sure the script has referenced X number of bars before you use a BarsAgo reference looking back that many bars.

                  Making sure you have enough bars in the data series you are accessing - https://ninjatrader.com/support/help...nough_bars.htm

                  Regarding #2, you will need to instantiate the Rectangle as a Rectangle object. This is demonstrated in the Help Guide documentation I linked. Note that the return value from Draw.Rectangle() is assigned to an object of type Rectangle, then the Rectangle object is accessed to modify the outline width. If object instantiating is unclear, I suggest reviewing some educational materials on C# to be more familiar.

                  Regarding #3, yes, if you want to always draw to the right side of the chart, where there is not bar slot, it would be recommended to use SharpDX rendering.

                  Comment


                    #10
                    Hello Jim,

                    I had solved Number 1 and 2. Perhaps its, because there are no active Datafeed at the weekend. On Monday I will know, if boths are working or not.

                    Number 3: I dont want, that the rectangles are drawed "in the future". I want, that they are ending at the current bar. For that I need a variable or more, because a fix value like "-100" means to draw the rectangles "in the future".

                    Best regards,
                    Renkotrader
                    Attached Files

                    Comment


                      #11
                      Hello Jim,

                      my Indicater works relative good, but there is a problem, that I cant solve.

                      You told me about the comparing - this Code I had implemented:
                      if (Close[0] > Close[Math.Min(CurrentBar, 1)])

                      1. with zones & without comparing: everything works, but the prior high and low (gray) are not correct
                      2. with zones & with comparing: no indicator at the chart
                      3. without zones & without comparing: the prior high and low wrong too
                      4. without zones & with comparing: the prior high and low correct

                      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
                      
                      namespace NinjaTrader.NinjaScript.Indicators
                      {
                      /// <summary>
                      /// Indikator Vortageshoch und -Tief
                      /// </summary>
                      public class VortageshochTief : Indicator
                      {
                      private DateTime currentDate = Core.Globals.MinDate;
                      private double currentHigh = 0;
                      private double currentLow = 0;
                      private double currentOpen = 0;
                      private double priorDayHigh = 0;
                      private double priorDayLow = 0;
                      private double priorDayOpen = 0;
                      private Data.SessionIterator sessionIterator;
                      private int BarIndexOfFirstBarOfSession;
                      
                      
                      //---------------------------------------------------------------------------------------------------------------------------
                      protected override void OnStateChange()
                      //---------------------------------------------------------------------------------------------------------------------------
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = "Vortageshoch und -Tief";
                      Name = "VortageshochTief";
                      IsAutoScale = false;
                      IsOverlay = true;
                      IsSuspendedWhileInactive = true;
                      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      DrawOnPricePanel = false;
                      PaintPriceMarkers = false;
                      }
                      else if (State == State.Configure)
                      {
                      currentDate = Core.Globals.MinDate;
                      currentHigh = 0;
                      currentLow = 0;
                      priorDayHigh = 0;
                      priorDayLow = 0;
                      sessionIterator = null;
                      }
                      else if (State == State.DataLoaded)
                      {
                      sessionIterator = new Data.SessionIterator(Bars);
                      }
                      else if (State == State.Historical)
                      {
                      if (!Bars.BarsType.IsIntraday)
                      {
                      Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PriorDayOHLCIntradayEr ror, TextPosition.BottomRight);
                      Log(NinjaTrader.Custom.Resource.PriorDayOHLCIntrad ayError, LogLevel.Error);
                      }
                      }
                      }
                      
                      
                      //---------------------------------------------------------------------------------------------------------------------------
                      protected override void OnBarUpdate()
                      //---------------------------------------------------------------------------------------------------------------------------
                      {
                      if (!Bars.BarsType.IsIntraday)
                      return;
                      
                      
                      // COMPARING
                      if (Close[0] > Close[Math.Min(CurrentBar, 1)])
                      
                      if (currentDate != sessionIterator.GetTradingDay(Time[0]) || currentOpen == 0)
                      {
                      priorDayHigh = currentHigh;
                      priorDayLow = currentLow;
                      
                      BarIndexOfFirstBarOfSession = CurrentBar;
                      
                      Rectangle Vortageshoch = Draw.Rectangle(this, "Vortageshoch", false, -1000, priorDayHigh, CurrentBar, priorDayHigh + (priorDayHigh - priorDayLow) * .04775, Brushes.DarkGray, Brushes.DarkGray, 30);
                      Vortageshoch.OutlineStroke.Width = 1;
                      Rectangle Vortagestief = Draw.Rectangle(this, "Vortagestief", false, -1000, priorDayLow, CurrentBar, priorDayLow - (priorDayHigh - priorDayLow) * .04775, Brushes.DarkGray, Brushes.DarkGray, 30);
                      Vortagestief.OutlineStroke.Width = 1;
                      
                      // ZONES
                      Rectangle ZoneOben1 = Draw.Rectangle(this, "ZoneOben1", false, CurrentBar - BarIndexOfFirstBarOfSession + 1, priorDayHigh - (priorDayHigh - priorDayLow) * .001, -1000, priorDayHigh - (priorDayHigh - priorDayLow) * .0955, Brushes.Transparent, Brushes.ForestGreen, 30);
                      ZoneOben1.OutlineStroke.Width = 1;
                      Rectangle ZoneOben2 = Draw.Rectangle(this, "ZoneOben2", false, CurrentBar - BarIndexOfFirstBarOfSession + 1, priorDayHigh - (priorDayHigh - priorDayLow) * .0955, -1000, priorDayHigh - (priorDayHigh - priorDayLow) * .191, Brushes.Transparent, Brushes.ForestGreen, 20);
                      ZoneOben2.OutlineStroke.Width = 1;
                      Rectangle ZoneUnten1 = Draw.Rectangle(this, "ZoneUnten1", false, CurrentBar - BarIndexOfFirstBarOfSession + 1, priorDayLow + (priorDayHigh - priorDayLow) * .001, -1000, priorDayLow + (priorDayHigh - priorDayLow) * .0955, Brushes.Transparent, Brushes.Red, 30);
                      ZoneUnten1.OutlineStroke.Width = 1;
                      Rectangle ZoneUnten2 = Draw.Rectangle(this, "ZoneUnten2", false, CurrentBar - BarIndexOfFirstBarOfSession + 1, priorDayLow + (priorDayHigh - priorDayLow) * .0955, -1000, priorDayLow + (priorDayHigh - priorDayLow) * .191, Brushes.Transparent, Brushes.Red, 20);
                      ZoneUnten2.OutlineStroke.Width = 1;
                      
                      currentOpen = Open[0];
                      currentHigh = High[0];
                      currentLow = Low[0];
                      currentDate = sessionIterator.GetTradingDay(Time[0]);
                      }
                      else
                      {
                      currentHigh = Math.Max(currentHigh, High[0]);
                      currentLow = Math.Min(currentLow, Low[0]);
                      }
                      }
                      
                      #region Properties
                      [Browsable(false)]
                      [XmlIgnore()]
                      public Series<double> PriorHigh
                      {
                      get { return Values[0]; }
                      }
                      
                      [Browsable(false)]
                      [XmlIgnore()]
                      public Series<double> PriorLow
                      {
                      get { return Values[1]; }
                      }
                      
                      #endregion
                      }
                      }
                      Please help me to solve this problem. Thank you!

                      Best regards,
                      Renkotrader



                      Attached Files
                      Last edited by Rainbowtrader; 11-08-2021, 10:55 AM.

                      Comment


                        #12
                        Hello Rainbowtrader,

                        Number 3: I dont want, that the rectangles are drawed "in the future". I want, that they are ending at the current bar. For that I need a variable or more, because a fix value like "-100" means to draw the rectangles "in the future".
                        You may use an endBarsAgo parameter of 0 to have the script end at the last bar on the chart. With Calculate.OnBarClose, BarsAgo 0 is the last completed bar. With Calculate.OnEachTick/OnPriceChange, BarsAgo 0 reflects the developing bar.

                        Drawing the rectangle to the right side of the chart, so the rectangle always ends on the price scale, would involve custom rendering.

                        With regards to your last post involving some values being correct and others are not, you will need to use debugging steps and be familiar with your calculation to be able to step back and see how it is producing the results you do not expect. This would involve tracing back to see which parts of the code calculate that value, add prints for those parts of the calculation, and then to run tests and check the prints in the output window to see which parts of that calculation are correct, and those that would need to be adjusted.

                        This would be specific to your script and your logic, and the the debugging steps would need to be taken by you as the script developer to understand the calculation/code and how it can be corrected.

                        If the debugging process is too difficult to breakdown an issue you are facing, you could always consider enlisting the services of a NinjaScript Consultant from our EcoSystem to assist in the development of some functionality you are having trouble with. If those services interest you, please let me know and I can have a colleague reach out with more information.

                        Comment


                          #13
                          Hello Jim,

                          thanks a lot for your help.

                          Rendering at the right side of the chart is not important or not.
                          The uncorrect high and low I had solved by the help from a friend.

                          Debugging is a thing, that I want to do, but this time there is a problem in not understanding the preparations before debugging can work.
                          Visual Studio 2019 is running, but I dont know, how I prepare a correct project map, that is needed for the cs-file from NinjaTrader 8.

                          Best regards,
                          Rainbowtrader

                          Comment


                            #14
                            Hello Rainbowtrader,

                            Debugging can be done with prints and the NinjaScript output window without using Visual Studio. The idea would to to reproduce behavior and use prints to see if actions are being reached, to check the values of conditions that control actions, and to print out parts of a certain parts of a calculation so you can check your work.

                            Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

                            If you are familiar with Visual Studio's Debugging features and want to attach the Visual Studio Debugger, please see the guide below.

                            Visual Studio Debugging - https://ninjatrader.com/support/help..._debugging.htm

                            Comment


                              #15
                              Hello Jim,

                              thanks a lot for your informations.
                              You will hear from me next time again

                              Have a great time!

                              Best regards,
                              Rainbowtrader

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              597 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              343 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              556 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              555 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X