Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Middle for High/Low Time Range

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

    Middle for High/Low Time Range

    Hi. I am trying to add the option of having a line plotted half way between the High and the Low for a specific time range. I am using the code from the High Low Time Range Indicator but I am having trouble with the code for calculating the half way point. Can anyone help? Thanks

    // Now that we have the start end end bars ago values for the specified time range we can calculate the highest high for this range
    double highestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo];

    // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range
    double lowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo];

    // Now that we have the start end end bars ago values for the specified time range we can calculate the middle for this range
    double midPoint = highestHigh + lowestLow * .5, (startBarsAgo - endBarsAgo) [endBarsAgo];

    #2
    double midPoint = highestHigh + lowestLow * .5;

    should work a-ok.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      If you're trying to get a midpoint (average), this will do the trick:
      Code:
      double midPoint = (highestHigh + lowestLow) / 2;
      AustinNinjaTrader Customer Service

      Comment


        #4
        Originally posted by eDanny View Post
        double midPoint = highestHigh + lowestLow * .5;

        should work a-ok.
        Hi EDanny. Thanks for your reply. I tried what I think you suggested and it just crammed everything together at the bottom of the page. Here's what I have. It's not my program I am just trying to add a center line to it. The program works great normally. Any help would be much appreciated otherwise I have to calculate it out every morning by hand. I can live with that but it would sure be nice not to have to. Thanks again.

        #region Variables
        // Wizard generated variables
        private int startHour = 9; // Default setting for StartHour
        private int startMinute = 30; // Default setting for StartMinute
        private int endHour = 10; // Default setting for EndHour
        private int endMinute = 15; // Default setting for EndMinute
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
        Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "HighestHigh"));
        Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "LowestLow"));
        Add(new Plot(Color.FromKnownColor(KnownColor.Purple), PlotStyle.Line, "MidPoint"));
        CalculateOnBarClose = true;
        Overlay = true;
        PriceTypeSupported = false;
        }

        private DateTime startDateTime;
        private DateTime endDateTime;

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        // Check to make sure the end time is not earlier than the start time
        if (EndHour < StartHour)
        return;

        //Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed
        if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0]))
        return;

        // If the stored date time date is not the same date as the bar time date, create a new DateTime object
        if (startDateTime.Date != Time[0].Date)
        {
        startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0);
        endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0);
        }

        // Calculate the number of bars ago for the start and end bars of the specified time range
        int startBarsAgo = GetBar(startDateTime);
        int endBarsAgo = GetBar(endDateTime);

        // Now that we have the start end end bars ago values for the specified time range we can calculate the highest high for this range
        double highestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo];

        // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range
        double lowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo];

        // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range
        double midPoint = highestHigh + lowestLow * .5;



        // Set the plot values
        HighestHigh.Set(highestHigh);
        LowestLow.Set(lowestLow);
        MidPoint.Set(midPoint);

        }

        #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 DataSeries HighestHigh
        {
        get { return Values[0]; }
        }

        [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 DataSeries LowestLow
        {
        get { return Values[1]; }
        }
        [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 DataSeries MidPoint
        {
        get { return Values[2]; }
        }
        [Description("")]
        [Category("Parameters")]
        public int StartHour
        {
        get { return startHour; }
        set { startHour = Math.Max(1, value); }
        }

        [Description("")]
        [Category("Parameters")]
        public int StartMinute
        {
        get { return startMinute; }
        set { startMinute = Math.Max(1, value); }
        }

        [Description("")]
        [Category("Parameters")]
        public int EndHour
        {
        get { return endHour; }
        set { endHour = Math.Max(1, value); }
        }

        [Description("")]
        [Category("Parameters")]
        public int EndMinute
        {
        get { return endMinute; }
        set { endMinute = Math.Max(1, value); }
        }
        #endregion

        Comment


          #5
          Originally posted by NinjaTrader_Austin View Post
          If you're trying to get a midpoint (average), this will do the trick:
          Code:
          double midPoint = (highestHigh + lowestLow) / 2;
          Worked like a charm. Thanks so much you saved me a lot of time.

          Best
          Robert

          Comment


            #6
            My bad, that shoulda been

            double midPoint = (highestHigh + lowestLow) * .5;

            which is the same functionally as

            double midPoint = (highestHigh + lowestLow) / 2;

            Either way, glad it works.
            eDanny
            NinjaTrader Ecosystem Vendor - Integrity Traders

            Comment


              #7
              Originally posted by eDanny View Post
              My bad, that shoulda been

              double midPoint = (highestHigh + lowestLow) * .5;

              which is the same functionally as

              double midPoint = (highestHigh + lowestLow) / 2;

              Either way, glad it works.
              Thanks for taking the time to help out.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ghoul, Today, 06:02 PM
              0 responses
              7 views
              0 likes
              Last Post ghoul
              by ghoul
               
              Started by Barry Milan, Yesterday, 10:35 PM
              6 responses
              18 views
              0 likes
              Last Post Barry Milan  
              Started by DanielSanMartin, Yesterday, 02:37 PM
              2 responses
              13 views
              0 likes
              Last Post DanielSanMartin  
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              13 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by terofs, Today, 04:18 PM
              0 responses
              12 views
              0 likes
              Last Post terofs
              by terofs
               
              Working...
              X