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

[NT8] How To Access Highest High and Lowest Low values from between time range?

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

    [NT8] How To Access Highest High and Lowest Low values from between time range?

    Hi everyone, I would like to know how can I get High, Low, Open, Close prices from time range, for example between 8pm nylt, and midnight nylt. I have found this code that gets and plots high / low from first 30 min range but that is based basically from single 30 min candle data. (At least from what i have understood).

    I am trying to learn how to access high low open close values based on time not candles number, not sure if nt8 does that newly created candle is [0] and history candles are more zero >=0.

    Does anyone have some examples? Or can explain to me how it could be possible done?

    For example Midnight candle open, so if candles == 00:00 get its values.
    Or how do I access series from 4pm, to 6pm, and get highest high and lowest low from between.

    Last thing would be get indicator limited to 3 days in the past, not from how many candlesticks are loaded as it will make NT laggy.

    Could you advise?
    Thanks everyone.

    Here is the code:

    Code:
    //
    // Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #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>
        /// </summary>
        public class OpeningRangeIndicator : Indicator
        {
            double highestPrice = 0.0;
            double lowestPrice = 0.0;
            bool   bFirst = true;
            double d30minbar = 0.0;
            
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = "Opening Range Indicator";
                    Name                        = "Opening Range Indicator";
                    IsOverlay                    = true;
                    IsSuspendedWhileInactive    = true;
    
                    AddPlot(Brushes.Red,        "Opening Range High");
                    AddPlot(Brushes.Red,        "Opening Range Low");
                    
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Minute, 30); //historical data load as when indicator is loaded. In this case 30 min candles.
                }
            }
    
            protected override void OnBarUpdate()
            {    
    
                if (BarsPeriod.BarsPeriodType == BarsPeriodType.Minute ) // if chart is set type minutes
                   {
                    if (bFirst) // check if its first bar
                    {
                        d30minbar = (30/BarsPeriod.Value)-1; // checks if its first 30 min candle created, if it isnt then sets bFirstvalue to false.
                        bFirst = false;
                    }
                    
                    if (CurrentBar < 20) // check is currentbar is less than 20 ? why? as if its 30 min range to show then CurrentBar should be check if its less than 30 candles. not 20
                    {
                        return; //if first 20 candles are loaded return nothing.
                    }
                    
                    
                    if( BarsPeriod.Value == 30) // check if BarsPeriod Value of it is 30 what is it checks for 30m timeframe or something else
                    {
                        if( Bars.BarsSinceNewTradingDay == 0) // if new bars are equal to 0 then it sets highstPrice value to Highs[1][0] so series is previous value of whatever is in [0] candle?
                        {
                            highestPrice = Highs[1][0]; // puts highest high price value from highs of candle [1] to highersPrice value
                            lowestPrice = Lows[1][0]; // same as above but for lows
                        }
                    }
                    
                    if (Bars.BarsSinceNewTradingDay > d30minbar)
                    {
                        HighOfRange[0] = highestPrice; //sets hP values of the range
                        LowOfRange[0] = lowestPrice; //sets hP values to lowOfRange
                    }
                   }
            }
    
            #region Properties
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> HighOfRange
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> LowOfRange
            {
                get { return Values[1]; }
            }
            #endregion
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private OpeningRangeIndicator[] cacheOpeningRangeIndicator;
            public OpeningRangeIndicator OpeningRangeIndicator()
            {
                return OpeningRangeIndicator(Input);
            }
    
            public OpeningRangeIndicator OpeningRangeIndicator(ISeries<double> input)
            {
                if (cacheOpeningRangeIndicator != null)
                    for (int idx = 0; idx < cacheOpeningRangeIndicator.Length; idx++)
                        if (cacheOpeningRangeIndicator[idx] != null &&  cacheOpeningRangeIndicator[idx].EqualsInput(input))
                            return cacheOpeningRangeIndicator[idx];
                return CacheIndicator<OpeningRangeIndicator>(new OpeningRangeIndicator(), input, ref cacheOpeningRangeIndicator);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.OpeningRangeIndicator OpeningRangeIndicator()
            {
                return indicator.OpeningRangeIndicator(Input);
            }
    
            public Indicators.OpeningRangeIndicator OpeningRangeIndicator(ISeries<double> input )
            {
                return indicator.OpeningRangeIndicator(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.OpeningRangeIndicator OpeningRangeIndicator()
            {
                return indicator.OpeningRangeIndicator(Input);
            }
    
            public Indicators.OpeningRangeIndicator OpeningRangeIndicator(ISeries<double> input )
            {
                return indicator.OpeningRangeIndicator(input);
            }
        }
    }
    
    #endregion
    
    ​

    Click image for larger version

Name:	image.png
Views:	229
Size:	66.3 KB
ID:	1287243

    #2
    Hello SuperUserek,

    Thanks for your post.

    HighestBar() and LowestBar() could be used to get the highest high and lowest low price.

    HighestBar(): https://ninjatrader.com/support/help...highestbar.htm
    LowestBar(): https://ninjatrader.com/support/help.../lowestbar.htm

    Here is a reference sample demonstrating how to calculate the highest high or lowest low for a specified time range which you might find helpful: https://ninjatrader.com/support/help...est_high_o.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply, unfortunately reference sample demonstrating how to calculate highest high or lowest low for specified time range is not working "PAGE NOT FOUND", like most of the links i have found on forum while researching. Im not sure how its possible, I just though that its been long time since post and it has been deleted. But since you have posted fresh link and page can not be found I am not sure how them links should / shouldnt work.
      But have gone back to help topics, and found correct link:
      https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?calculating_the_high est_high_o.htm
      Thanks anyway. I hope ill get to understand it well enough to do what I want to do with it.
      ==== EDIT
      Looks like Help page links are broken once added as link option here in posts as reply, Link above worked for me from help topics, as soon as ive added "correct link" doesnt redirect correctly.
      But added it to short url here and once clicked it redirects fine to the right page
      .

      =========More info please
      Can You please assist with limit indicator to be only drawn back last 5 days?
      Would logic added with bar since work to just simply "return" nothing while calculating on the beginning work? Obviously we would need to create new time and date then compare it to bar since, if date is less than for example Today - 5 days then return nothing?
      That is theory of course.
      Regards
      Last edited by SuperUserek; 01-24-2024, 12:29 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,290 views
      1 like
      Last Post jgualdronc  
      Started by Touch-Ups, Today, 10:36 AM
      0 responses
      8 views
      0 likes
      Last Post Touch-Ups  
      Started by geddyisodin, 04-25-2024, 05:20 AM
      11 responses
      61 views
      0 likes
      Last Post halgo_boulder  
      Started by Option Whisperer, Today, 09:55 AM
      0 responses
      8 views
      0 likes
      Last Post Option Whisperer  
      Started by halgo_boulder, 04-20-2024, 08:44 AM
      2 responses
      24 views
      0 likes
      Last Post halgo_boulder  
      Working...
      X