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

PriorDayOHLC Problem

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

    PriorDayOHLC Problem

    Hi,

    I'm trying to use the Prior Day High, Low, & Close to make some math. The method I use is:

    PriorDayOHLC().currentHigh[0]
    PriorDayOHLC().currentLow[0]
    PriorDayOHLC().currentClose[0]
    and PriorDayOHLC().currentOpen[0] but when i try to compile the following message appears:

    'NinjaTrader.Indicator.PriorDayOHLC.currentHigh' is inaccessible due to its protection level
    'NinjaTrader.Indicator.PriorDayOHLC.currentLow' is inaccessible due to its protection level
    'NinjaTrader.Indicator.PriorDayOHLC.currentClose' is inaccessible due to its protection level
    'NinjaTrader.Indicator.PriorDayOHLC.currentOpen' is inaccessible due to its protection level

    any idea?

    Thanks

    #2
    If you are trying to get the previous day's OHLC you should use PriorDayOHLC().PriorHigh[0], PriorDayOHLC().PriorLow[0], etc.

    For current day OHL you can use CurrentDayOHL().CurrentLow[0] etc.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Solved,

      Thanks

      Comment


        #4
        I just noticed something interesting with the behavior of PriorDayOHLC().PriorHigh[0] etc. During real-time the PriorDayOHLC updates per tick and after the first tick of the day the values seem to revert to the values of the day prior to the previous day. That's a bit confusing so here is my Output Window entries. This is on a daily chart.

        Code:
        7/13/2007 12:00:00 AM
        134.4 <-prior high
        128.8 <-prior low
        7/16/2007 12:00:00 AM <-first tick of day
        133.7
        131.31
        7/16/2007 12:00:00 AM <-subsequent ticks
        134.4
        128.8
        As you can see the value on the first tick of the day was correct, but as it comes back to the OnBarUpdate() it reverts back to the value of 7/13 which is the high/low of 7/12 despite the date being 7/16.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          i tried to reproduce the behaviour you got, but didn't succeed. Can you please tell me, which exact steps you take, to get this ? Do you use some custom indicator to reproduce that ?

          If yes, please send it to:
          christian AT ninjatrader DOT com

          Thank you,
          Christian
          ChristianSenior Software Developer

          Comment


            #6
            Yes Christian I am using a custom indicator. This is basically all I do in my code to reproduce the error.

            Code:
            Print(Time[0].Date.ToString());
            Print(PriorDayOHLC().PriorHigh[0]);
            Print(PriorDayOHLC().PriorLow[0]);
            prevhigh.Set(PriorDayOHLC().PriorHigh[0]);
            prevlow.Set(PriorDayOHLC().PriorLow[0]);
            Please note that if I did not do the *.Set on my two plots the PriorDayOHLC() remains correct on incoming ticks.

            If my code was
            Code:
            Print(Time[0].Date.ToString());
            Print(PriorDayOHLC().PriorHigh[0]);
            Print(PriorDayOHLC().PriorLow[0]);
            This would be my output.
            Code:
            7/16/2007 12:00:00 AM
            137.85
            134.07
            7/17/2007 12:00:00 AM
            139.96
            137.5
            7/17/2007 12:00:00 AM
            139.96
            137.5
            Otherwise the output would be
            Code:
            7/16/2007 12:00:00 AM
            137.85
            134.07
            7/17/2007 12:00:00 AM
            139.96
            137.5
            7/17/2007 12:00:00 AM
            137.85
            134.07
            Let me know if you still need my custom indicator. I am not on my main computer at the moment and don't have access to it.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              The PriorDayOHLC should only be used on intraday intevals. We will make a change in NT 6.5 to reflect this.

              If you programmatically want to access prior session OHLCV values, please use GetSessionBar().



              There is a known issue with GetSessionBar() that will be resolved in NT 6.0.1000.4.

              For plotting prior day OHLC values on a chart, use a 1 period SMA and displace it by a value of 1.
              RayNinjaTrader Customer Service

              Comment


                #8
                OHLC for cash market hours

                Hacked this together to use 09:30 - 16:15 for the indicator lines (which means will draw the lines on a 24 hour chart, but the lines are based on cash market hours), may run a bit slow, but seems functional. Basically a mod of the current OHLC.

                #region Variables

                // Wizard generated variables
                // User defined variables (add any user defined variables below)
                private DateTime currentDate = Cbi.Globals.MinDate;
                private double currentOpen = 0;
                private double currentHigh = 0;
                private double currentLow = 0;
                private double currentClose = 0;

                private bool beenHere = false;

                private double tempHigh = 0;
                private double tempLow = 0;

                private bool showOpen = true;
                private bool showHigh = true;
                private bool showLow = true;
                private bool showClose = true;
                #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.Hash, "Prior Open"));
                Add(new Plot(Color.Green, PlotStyle.Hash, "Prior High"));
                Add(new Plot(Color.Red, PlotStyle.Hash, "Prior Low"));
                Add(new Plot(Color.Firebrick, PlotStyle.Hash, "GAP"));

                Plots[0].Pen.DashStyle = DashStyle.Dash;
                Plots[3].Pen.DashStyle = DashStyle.Dash;

                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()
                {
                DateTime candleDayClose = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 16, 15, 0, 0);
                DateTime yesterdayClose = candleDayClose.AddDays(-1);
                int barsAgo = CurrentBar - Bars.GetBar(yesterdayClose);
                currentClose = Close[barsAgo];
                if (ShowClose) PriorClose.Set(currentClose);

                DateTime candleDayOpen = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0, 0);
                DateTime yesterdayOpen = candleDayOpen.AddDays(-1);
                int barsAgo2 = CurrentBar - Bars.GetBar(yesterdayOpen);
                currentOpen = Close[barsAgo2];
                if (ShowClose) PriorOpen.Set(currentOpen);


                // If the current data is not the same date as the current bar then its a new day
                if ( (currentDate != Time[0].AddSeconds(-1).Date || currentOpen == 0))
                {
                // The current day OHLC values are now the prior days value so set
                // them to their respect indicator series for plotting
                if (currentOpen != 0)
                {
                // if (ShowOpen) PriorOpen.Set(currentOpen);
                if (ShowHigh) PriorHigh.Set(currentHigh);
                if (ShowLow) PriorLow.Set(currentLow);
                // if (ShowClose) PriorClose.Set(currentClose);
                }

                // Initilize the current day settings to the new days data
                // currentOpen = Open[0];
                currentHigh = High[0];
                currentLow = Low[0];
                // currentClose = Close[0];
                currentDate = Time[0].AddSeconds(-1).Date;
                } else {
                // Set the prior days values to the prior day so we get a straight line
                if (PriorOpen.Count > 1)
                {
                // if (ShowOpen) PriorOpen.Set(PriorOpen[1]);
                if (ShowHigh) PriorHigh.Set(PriorHigh[1]);
                if (ShowLow) PriorLow.Set(PriorLow[1]);
                // if (ShowClose) PriorClose.Set(PriorClose[1]);
                }
                }

                if(candleDayOpen < Time[0] && Time[0] < candleDayClose)// The current day is the same day within cash hours
                {
                // Set the current day OHLC values
                currentHigh = Math.Max(currentHigh, High[0]);
                currentLow = Math.Min(currentLow, Low[0]);
                //currentClose = Close[0];


                }

                }

                Comment


                  #9
                  Your OHLC

                  Can you send me the file? I can't seem to get this to work for me.

                  Thanks,

                  Bobby

                  Comment


                    #10
                    PriorWeekOHLC and PriorMonthOHLC

                    Following on from this how can NT plot on the current daily chart the:

                    PriorWeekOHLC ?
                    PriorMonthOHLC ?
                    Also the OHLC of n days ago. ?
                    Daily Pivots from N days ago ?

                    Regards and thx for any input guys.
                    Last edited by elliot5; 08-03-2011, 05:58 AM.

                    Comment


                      #11
                      Hello,

                      Thanks for the note.

                      We do not have indicator build into NinjaTrader to do this automatically.

                      This would need to be custom coded.

                      You would need to use High[0] and then take the number of bars back you want to check agianst. Then output the Highest value of the High's as your current week OHLC and previous.

                      You can also use the High[9] Low[9] Close[9] and Open[9] to plot the OHLC of 9 bars back, replace the 9 with the number of days back you want to plot.

                      Then for the pivots this would need to be manually calculated. Our pivots only work on intraday charts and not on daily chart.


                      If your not a programmer let me know and I can assist with finding a NinjaScript consultant.

                      Let me know if I can be of further assistance.

                      Comment


                        #12
                        Thankyou for the reply. I will code this myself.

                        Comment


                          #13
                          You can use the SessionPivots indicators here:



                          Prior week, month HLC is included and shown with the weekly and monthly pivot indicators. If you look for a n-day rolling pivots indicator, you can find it here.

                          The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies

                          Comment


                            #14
                            Originally posted by Harry View Post
                            You can use the SessionPivots indicators here:



                            Prior week, month HLC is included and shown with the weekly and monthly pivot indicators. If you look for a n-day rolling pivots indicator, you can find it here.

                            http://www.bigmiketrading.com/free_d...load.html?view
                            Thanks Harry. I notice that the indicator looks at the current week, and current month OHL , I dont think it plots the priorMonth OHLC and PriorWeek OHLC or perhaps I am missing something,

                            Regards and thanks

                            Comment


                              #15
                              Originally posted by everington_f View Post
                              Thanks Harry. I notice that the indicator looks at the current week, and current month OHL , I dont think it plots the priorMonth OHLC and PriorWeek OHLC or perhaps I am missing something,

                              Regards and thanks
                              There are six indicators included. The pivots - not the OHL indicators - show the prior month HLC, but not the open of the prior month.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Barry Milan, Yesterday, 10:35 PM
                              5 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              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
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post nandhumca  
                              Working...
                              X