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

StartDateTime in continuation pattern

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

    StartDateTime in continuation pattern

    Hi,
    I'd like to define the startDateTime in hourly basis on Range Chart. How could I do the following? (The code of course is not correct) Thanks in advance.

    startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9||10||11, 40, 0);

    #2
    Hello Kelvin,

    Not sure I follow. Session times are defined in the chart properties for version 6.5, or by the Session template in version 7. Please clarify a bit what you're trying to do.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,
      I'd like to the following :-

      startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9||10||11, 40, 0);
      endDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9||10||11, 50, 0);


      int startBarsAgo1 = GetBar( startDateTime1);
      int endBarsAgo1 = GetBar( endDateTime1);
      double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];
      double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];

      Comment


        #4
        Kelvin,

        I see what you're trying to do. It looks like you've been working from the reference sample below:


        Using || operator is not supported in that field. You would have to create a new dateTime object for each DateTime that you are trying to capture.

        startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 40, 0);
        startDateTime2 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 10, 40, 0);
        startDateTime3 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 11, 40, 0);
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          I've tried the following and found that:

          startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 20, 15, 0);
          endDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 20, 29, 59);

          int startBarsAgo1 = GetBar( startDateTime1);
          int endBarsAgo1 = GetBar( endDateTime1);

          double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];
          double lowestLow1 = MIN(Low, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];

          h1.Set (highestHigh1);
          l1.Set ( lowestLow1);

          (1) If the high or low of the first range bar is the highest high or lowest low of the specifief time range ,then it is not included in the plot and the plot doesn't plot from the beginning.Any advice to solve this?
          (2) How to defined the plot function to plot within the specified time range? (eg. plot from startBarsAgo1 To endBarsAgo1)
          (3) I've usdeup
          Hi,
          I've tried the following and found that:

          startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 20, 15, 0);
          endDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 20, 29, 59);

          int startBarsAgo1 = GetBar( startDateTime1);
          int endBarsAgo1 = GetBar( endDateTime1);

          double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];
          double lowestLow1 = MIN(Low, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];

          h1.Set (highestHigh1);
          l1.Set ( lowestLow1);

          (1) If the high or low of the first range bar is the highest high or lowest low of the specifief time range ,then it is not included in the plot and the plot doesn't plot from the beginning.Any advice to solve this?
          (2) How to defined the plot function to plot within the specified time range? (eg. plot from startBarsAgo1 To endBarsAgo1)
          (3) I've used TextPosition.Center,TextPosition.TopLeftt and TextPosition.BottomLeft.How can I add Drawtext just next to the above three for comparing purposes?
          Attached Files
          Last edited by kelvin johnson; 06-16-2010, 01:15 PM.

          Comment


            #6
            Hi Kelvin,

            1) Not sure that's the cause here. Maybe need to experiment with different start / stop times to fit earlier bars? When you're looking at the first bar, there's no way for it to know that it will end up being the highest high or lowest low of the specified time range. If it continues not to work as you expect, let me know an example chart series I could see this on. To duplicate your setup, I'd need instrument, interval, Chart session times, and the time filter you're using.

            2) Please clarify what you're looking to do. Plots are synecd to bars. They'll plot according to their value on that particular bar.

            3) You can draw text using a y position and barsAgo. See supported overloads for DrawText at the link below:
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Hi Ryan,
              (1) I'm using FDAX 10-06, 1 RangeAlt, (Dated June 16th. Local PC time GMT+1 )

              (2) Attachment 1 : The first bar high happened to be the highest high of the specified time range and not plotted throughout the specifief time range.
              (a) Chart session times 21:15 -- 21:45
              (b)startDateTime 211500, endDateTime 212959

              startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 21, 15, 0);
              endDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 21, 29, 59);

              int startBarsAgo1 = GetBar( startDateTime1);
              int endBarsAgo1 = GetBar( endDateTime1);

              double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];
              double lowestLow1 = MIN( Low, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];

              h1.Set (highestHigh1);
              l1.Set ( lowestLow1);

              DrawRegion("Reg1", startBarsAgo1, endBarsAgo1, h1, l1, Color.Transparent, Color.DarkRed, 10);

              (3) Attachment 2 : The first bar low happened to be the lowest low of the specified time range and not plotted throughout the specifief time range.
              (a) Chart session times 16:40 --17:00
              (b)startDateTime 164000, endDateTime 164959

              startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 40, 0);
              endDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 49, 59);

              int startBarsAgo1 = GetBar( startDateTime1);
              int endBarsAgo1 = GetBar( endDateTime1);

              double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];
              double lowestLow1 = MIN( Low, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];

              h1.Set (highestHigh1);
              l1.Set ( lowestLow1);

              DrawRegion("Reg1", startBarsAgo1, endBarsAgo1, h1, l1, Color.Transparent, Color.DarkRed, 10);

              (4) Attachment 3 : The first bar high and low happened to be lower and higher than the highest high and lowest low of the specified time range and was plotted eventually after the first bar high or low was taken off.
              (a) Chart session times 15:45 -- 16:05
              (b)startDateTime 154500, endDateTime 155959

              startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 15, 45, 0);
              endDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 15,59, 59);

              int startBarsAgo1 = GetBar( startDateTime1);
              int endBarsAgo1 = GetBar( endDateTime1);

              double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];
              double lowestLow1 = MIN( Low, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];

              h1.Set (highestHigh1);
              l1.Set ( lowestLow1);

              DrawRegion("Reg1", startBarsAgo1, endBarsAgo1, h1, l1, Color.Transparent, Color.DarkRed, 10);

              (5) Checking from my screen, it seems that the PLOTS (Green lines on all the attachment) start to plot on the 21st bar rather than the first bar and extended to the current bar.

              (6) I want the PLOT to do as what the DrawRegion function does. Start plotting from startBarsAgo1 and end plotting at endBarsAgo1.(no extension beyond endBarsAgo1).
              Attached Files

              Comment


                #8
                (a) Attachment 3. (continue from #7)
                Attached Files

                Comment


                  #9
                  Kelvin, indicators require a minimum of 20 bars to work correctly. Perhaps the issues here stem from that fact. You may want to add checks to review the first 20 bars when your script starts actually working on the 21st bar because the script will have, in essence, "missed" the first 20 bars. That is why your plots start on the 21st bar instead of the first bar.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    Hi,
                    (1) After including 20 more bars ,it starts to plot from the first bar. Can the PLOTS plot according to the specified time range? Thanks.
                    (2) It still failed to check the first bar high or low for the specified time range. (Please compare the attachment with the first attachment on #7)
                    Attached Files

                    Comment


                      #11
                      Kelvin, the plots are plotted according to the bar number, not by time.

                      As for the second part of your post, what code did you add to cycle through the first 20 bars to pick out the highest high and lowest low? Could you post the complete code sample you're using here so we can see the big picture?
                      AustinNinjaTrader Customer Service

                      Comment


                        #12
                        Hi,

                        (1) I'm not adding any code to cycle through the first 20 bars. Initially I set my session begin time (in chart propertities) the same as "startDateTime1" in my code. Next I changed my session begin time 15 minutes ahead of the "startDateTime1" and managed to PLOT from the first bar.

                        (2)The complete code I'm using.

                        #region Using declarations
                        using System;
                        using System.ComponentModel;
                        using System.Diagnostics;
                        using System.Drawing;
                        using System.Drawing.Drawing2D;
                        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>
                        ///
                        /// </summary>
                        [Description("")]
                        public class BTPTest1 : Indicator
                        {
                        #region Variables
                        // Wizard generated variables

                        // 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(new Pen(Color.Lime, 1), PlotStyle.Hash, "h1"));
                        Add(new Plot(new Pen(Color.Lime, 1), PlotStyle.Hash, "l1"));

                        Plots[0].Pen.DashStyle = DashStyle.Solid;
                        Plots[1].Pen.DashStyle = DashStyle.Solid;

                        CalculateOnBarClose = false;
                        Overlay = true;
                        PriceTypeSupported = false;
                        }

                        private DateTime startDateTime1;
                        private DateTime endDateTime1;

                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                        if (ToTime(21, 14, 59) > ToTime(Time[0]))
                        return;

                        startDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 21, 15, 0);
                        endDateTime1 = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 21, 29, 59);

                        int startBarsAgo1 = GetBar( startDateTime1);
                        int endBarsAgo1 = GetBar( endDateTime1);

                        double highestHigh1 = MAX(High, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];
                        double lowestLow1 = MIN(Low, startBarsAgo1 - endBarsAgo1) [endBarsAgo1];

                        h1.Set (highestHigh1);
                        l1.Set ( lowestLow1);

                        DrawRegion("Reg1", startBarsAgo1, endBarsAgo1, h1, l1, Color.Transparent, Color.DarkRed, 10);

                        }
                        #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 h1
                        {
                        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 l1
                        {
                        get { return Values[1]; }
                        }


                        #endregion
                        }
                        }
                        #region NinjaScript generated code. Neither change nor remove.
                        // This namespace holds all indicators and is required. Do not change it.
                        namespace NinjaTrader.Indicator
                        {
                        public partial class Indicator : IndicatorBase
                        {
                        private BTPTest1[] cacheBTPTest1 = null;
                        private static BTPTest1 checkBTPTest1 = new BTPTest1();
                        /// <summary>
                        ///
                        /// </summary>
                        /// <returns></returns>
                        public BTPTest1 BTPTest1()
                        {
                        return BTPTest1(Input);
                        }
                        /// <summary>
                        ///
                        /// </summary>
                        /// <returns></returns>
                        public BTPTest1 BTPTest1(Data.IDataSeries input)
                        {
                        if (cacheBTPTest1 != null)
                        for (int idx = 0; idx < cacheBTPTest1.Length; idx++)
                        if (cacheBTPTest1[idx].EqualsInput(input))
                        return cacheBTPTest1[idx];
                        BTPTest1 indicator = new BTPTest1();
                        indicator.BarsRequired = BarsRequired;
                        indicator.CalculateOnBarClose = CalculateOnBarClose;
                        indicator.Input = input;
                        indicator.SetUp();
                        BTPTest1[] tmp = new BTPTest1[cacheBTPTest1 == null ? 1 : cacheBTPTest1.Length + 1];
                        if (cacheBTPTest1 != null)
                        cacheBTPTest1.CopyTo(tmp, 0);
                        tmp[tmp.Length - 1] = indicator;
                        cacheBTPTest1 = tmp;
                        Indicators.Add(indicator);
                        return indicator;
                        }
                        }
                        }
                        // This namespace holds all market analyzer column definitions and is required. Do not change it.
                        namespace NinjaTrader.MarketAnalyzer
                        {
                        public partial class Column : ColumnBase
                        {
                        /// <summary>
                        ///
                        /// </summary>
                        /// <returns></returns>
                        [Gui.Design.WizardCondition("Indicator")]
                        public Indicator.BTPTest1 BTPTest1()
                        {
                        return _indicator.BTPTest1(Input);
                        }
                        /// <summary>
                        ///
                        /// </summary>
                        /// <returns></returns>
                        public Indicator.BTPTest1 BTPTest1(Data.IDataSeries input)
                        {
                        return _indicator.BTPTest1(input);
                        }
                        }
                        }
                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                        public partial class Strategy : StrategyBase
                        {
                        /// <summary>
                        ///
                        /// </summary>
                        /// <returns></returns>
                        [Gui.Design.WizardCondition("Indicator")]
                        public Indicator.BTPTest1 BTPTest1()
                        {
                        return _indicator.BTPTest1(Input);
                        }
                        /// <summary>
                        ///
                        /// </summary>
                        /// <returns></returns>
                        public Indicator.BTPTest1 BTPTest1(Data.IDataSeries input)
                        {
                        if (InInitialize && input == null)
                        throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
                        return _indicator.BTPTest1(input);
                        }
                        }
                        }
                        #endregion

                        Comment


                          #13
                          Kevin, unfortunately we're not clear what the exact issue is here and can't really debug this code for you - for the 20 bars non plot at chart start - this is expected and called the unstable period for indicator, you can turn on to plot this via the chart properties.

                          Is that what you're after?

                          Thanks
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Hi,
                            (1) "NO PLOT for the first 20 bars" has been solved.
                            (2) The first bar high or low of the specified time range were unchecked [Please refer to #7 (2) (3) (4) and #8].

                            Comment


                              #15
                              Kelvin,

                              Unfortunatley we are unable to debug this for you. Please see the reference sample below on debugging steps. Try and simplify as much as you can and use Print statements to verify values.


                              If you would like this developed professionally, consider hiring a 3rd party NinjaScript consultant. List is available at the link below:
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              26 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, Yesterday, 09:53 PM
                              2 responses
                              49 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Kensonprib, 04-28-2021, 10:11 AM
                              5 responses
                              192 views
                              0 likes
                              Last Post Hasadafa  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,234 views
                              0 likes
                              Last Post xiinteractive  
                              Working...
                              X