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

1st Hour High/Low

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

    1st Hour High/Low

    Hi, does anyone know where I can find, or how I can make an indicator that plots a line showing the 1st hour's High/Low of the session?

    Thanks,

    PijamaTrader



    #2
    imported post

    A system indicator does not exist but you can program one in NinjaScript. If you are new to programming, this will require a learning curve. If you have programming background, please see the Help Guide section for NinjaScript. There are some indicator development tutorials to get you started. You can also look at the code for the PriorDayOHLC to get an idea of how to go about programming the logic for such an indicator.

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      I am also interested in this indicator.

      Is there a function that allows you to store values from a given time/date?

      thanks

      Comment


        #4
        imported post

        No there is not.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          This is the logic I have but would like some help with the translation to get me started.

          THanks

          Qi

          // New day settings
          if ( DateTime[0]<>Date[1] )
          DateInFromTo= (Date>=iFromYYYMMDD && Date<=iToYYYMMDD);
          bool FirstTrade=true;
          double RangeH=H;
          double RangeL=L; // first bars High Low are Ranges h&l
          TimeH=Time;
          TimeL=Time;


          // Range settings
          If L<LowD(0)[1] then TimeL=Time; {if new H or L, remember the time of H or L}
          If H>HighD(0)[1] then TimeH=Time;

          If Time=OpenRangeTime then begin // if openning range is finished
          RangeH=HighD(0); RangeL=LowD(0); RangeHtime=TimeH; RangeLtime=TimeL; end; // remember Range parameters

          Comment


            #6
            imported post

            I suggest reviewing some of our system indicator source files. Check out the @PreviousDayOHL to get an idea of how this can be done.

            Ray
            RayNinjaTrader Customer Service

            Comment


              #7
              In NT, how do I recall the High or Low of a given time?

              Can I declare a variable representing 930am EST and another as 1000a EST as below?

              e.g.

              private double start_time = 0930;
              private double end_time = 1000;

              thanks

              Comment


                #8
                There seems to be a few requests to the OR lines. So I will start providing my logic. Let me know if it needs to be corrected.

                Thanks

                #region Using declarations
                using System;
                using System.Diagnostics;
                using System.Drawing;
                using System.Drawing.Drawing2D;
                using System.ComponentModel;
                using System.Xml.Serialization;
                using NinjaTrader.Cbi;
                using NinjaTrader.Data;
                using NinjaTrader.Gui.Chart;
                #endregion

                // This namespace holds all indicators and is required. Do not change it.
                namespace NinjaTrader.Indicator
                {
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                [Description("Opening Range Breakout")]
                [Gui.Design.DisplayName("OR Breakout")]
                public class OpeningRange : Indicator
                {
                #region Variables

                private DateTime currentDate = Cbi.Globals.MinDate;
                private int start_time = 0930;
                private int start_time = 1000;
                private int PeriodHigh = 0;
                private int PeriodLow = 9999;

                #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.Orange, PlotStyle.Line, "PeriodHigh"));
                Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodLow"));

                AutoScale = false;
                CalculateOnBarClose = false; // Call 'OnBarUpdate' on every tick
                Overlay = true; // Plots the indicator on top of price
                }

                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                if (currentDate != Time[0].Date)//if new day
                {
                PeriodHigh = 0; // re-initialize PeriodHigh,PeriodLow for the new day
                PeriodLow = 9999;
                }
                if (StartTime <= Time[0] || Time[0] <= EndTime) {
                if (High[0] > PeriodHigh) { PeriodHigh = High ; }
                if (Low[0] < PeriodLow) { PeriodLow = Low ; }
                PeriodLow = Low ;
                }
                }
                #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 Plot0
                {
                get { return Values[0]; }
                }

                #endregion
                }
                }

                Comment


                  #9
                  I have uploaded part of my code but still getting error messages.

                  The name 'StartTime' does not exist in the current context
                  " " 'EndTime' " " " " " " "

                  Any help in the code is appreciated

                  thanks
                  Attached Files

                  Comment


                    #10
                    StartTime --> You have not declared this anywhere, that's why it says it does not exist. Even if you rectify this, your logic will not work. Please review the following Help Guide section.

                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Hi

                      I changed the code to the following but it still doesn't plot the lines. Any help is appreciated. THe code compiled correctly.

                      protected override void Initialize()
                      {
                      Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodHigh"));
                      Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodLow"));

                      AutoScale = false;
                      CalculateOnBarClose = false; // Call 'OnBarUpdate' on every tick
                      Overlay = true; // Plots the indicator on top of price
                      }

                      protected override void OnBarUpdate()
                      {
                      if (currentDate != Time[0].Date)//if new day
                      {
                      PeriodHigh = 0; // re-initialize PeriodHigh,PeriodLow for the new day
                      PeriodLow = 9999;
                      }
                      if (ToTime(Time[0]) > start_time && ToTime(Time[0]) < end_time) {
                      if (High[0] > PeriodHigh) { PeriodHigh = High[0] ; }
                      if (Low[0] < PeriodLow) { PeriodLow = Low[0] ; }

                      }
                      }
                      Attached Files

                      Comment


                        #12
                        Hi,

                        Its not plotting since you are not setting any plot values. I would scrap this indicator and start through the wizard and add plots named PeriodHigh and PeriodLow and then have the wizard generate all of the code required.

                        Then add back your logic and when you have to set the value of your plots, you would do something like:

                        PeriodHigh.Set(plotValueHere);
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          I think I am very close but I got 1 error message.

                          Cannot apply indexing with [] to an expression of type 'double'
                          Attached Files

                          Comment


                            #14
                            PHigh is a variable not an array that can be indexed.

                            Should be PeriodHigh.Set(PHigh);
                            RayNinjaTrader Customer Service

                            Comment


                              #15
                              Hi

                              The code works now but my logic is flawed. How do I use the following properties?

                              Bars.GetSessionBar(int sessionsAgo).High

                              Bars.GetSessionBar(int sessionsAgo).Low

                              Trying to gather the highest high and lowest low of session from start period to end period.

                              Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              31 responses
                              817 views
                              1 like
                              Last Post NinjaTrader_Adrian  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              5 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by swestendorf, Today, 11:14 AM
                              2 responses
                              6 views
                              0 likes
                              Last Post NinjaTrader_Kimberly  
                              Started by Mupulen, Today, 11:26 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Mupulen
                              by Mupulen
                               
                              Started by Sparkyboy, Today, 10:57 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X