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

Reference dataseries of another indicator in another timeframe

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

    Reference dataseries of another indicator in another timeframe

    I'm having difficulty accessing the dataseries of an indicator that uses day bars and applying that data in a second indicator using minute bars.

    To keep things simple, let's say that I have an indicator (HiLoOpen attached below) that plots the average of the previous day high, the previous day low, and the current day open:

    (High[1]+Low[1]+Open[0])/3

    I would like to use a second indicator(HiLoOpenINTRADAY attached below) to plot this value as a horizontal line on an intraday minute chart.

    Unfortunately, I have been unable to plot the horizontal line based on the previous day high, previous day low, and the current day open. Instead I am getting a horizontal line based on the previous minute high, previous minute low, and the current minute open.

    I've looked through the NinjaTrader 8 help guide and studied the BarsPeriod function and found a reference sample that is similar to my objective (Synchronizing a DataSeries object to a secondary time frame -- http://ninjatrader.com/support/forum...ead.php?t=3572). I've also found other threads about secondary data series, but I seem to be missing part of the picture.

    Using the GetDayBar() and CurrentDayOHL() functions is unfortunately not an option--the attached indicators are extremely simple and only for the sake of example; the actual indicators I will be using are far more complex and it would be impractical to use either the GetDayBar() or the CurrentDayOHL() functions.

    There must be a way to reference the dataseries of another indicator in another timeframe.

    If anyone has any ideas, any feedback would be great!
    Attached Files

    #2
    Hi h1000,

    How are you attempting to get these values?

    Are you adding a secondary series with AddDataSeries() and supplying the Closes[barsInProgress index] to the indicator as the input series?

    Are you calling PriorDayOHLC() in the indicator?

    Below is a link to the PriorDayOHLC() indicator.


    A link to an official reference sample that demonstrates how to add series.
    http://www.ninjatrader.com/support/f...ead.php?t=6652

    A link to the help guide on the AddDataSeries() method.
    http://ninjatrader.com/support/helpG...dataseries.htm

    A link to the help guide on BarsInProgress.
    http://ninjatrader.com/support/helpG...inprogress.htm

    And a link to the help guide on Multi-Time Frame & Instruments. Please see the section 'How Bar Data is Referenced', and 'Accessing the Price Data in a Multi-Bars NinjaScript'.
    http://ninjatrader.com/support/helpG...nstruments.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the information and links!

      I've attached a new indicator (please see attached indicator HiLoOpenVersion2) which I created after reading through the suggestions. Unfortunately, I must be missing something as the indicator still isn't plotting the horizontal line.

      Originally posted by NinjaTrader_ChelseaB View Post
      Are you adding a secondary series with AddDataSeries() and supplying the Closes[barsInProgress index] to the indicator as the input series?
      I have added a secondary data series, but I'm not sure how to "supply the Closes" as mentioned above. Could you give me an example to clarify this?

      Originally posted by NinjaTrader_ChelseaB View Post
      Are you calling PriorDayOHLC() in the indicator?
      I would prefer to find a solution that doesn't rely on the PriorDayOHLC function. As I mentioned in my original post, the attached indicators are extremely simple and only for the sake of example; the actual indicators I will be using are far more complex. So I would prefer to find a way to do this that would accommodate more complex data points than simply the previous day OHLC.

      Would it be possible for you to review the version2 indicator that I have attached and point me in the right direction to get it to work?
      Attached Files

      Comment


        #4
        Originally posted by h1000 View Post
        Thanks for the information and links!

        I've attached a new indicator (please see attached indicator HiLoOpenVersion2) which I created after reading through the suggestions. Unfortunately, I must be missing something as the indicator still isn't plotting the horizontal line.



        I have added a secondary data series, but I'm not sure how to "supply the Closes" as mentioned above. Could you give me an example to clarify this?



        I would prefer to find a solution that doesn't rely on the PriorDayOHLC function. As I mentioned in my original post, the attached indicators are extremely simple and only for the sake of example; the actual indicators I will be using are far more complex. So I would prefer to find a way to do this that would accommodate more complex data points than simply the previous day OHLC.

        Would it be possible for you to review the version2 indicator that I have attached and point me in the right direction to get it to work?
        In the calling class, you must add a second daily DataSeries with AddDataSeries(), then where you want to reference the daily data series, you feed it with an input of BarsArray[1] to get the output value that you are seeking. That is pretty much the example detailed in the NT Manual.

        ref: http://ninjatrader.com/support/helpG.../barsarray.htm
        Last edited by koganam; 04-04-2017, 06:56 AM. Reason: Corrected grammar.

        Comment


          #5
          Hello h1000,

          When I add the indicator to an ES chart with 5 days to load the indicator appears to be drawing a line at 0.

          Looking at the code, I see that at least 11 trading days of historical data (not including weekends) are required before the MyPriceLevel will be set and the line will move from 0 to a calculated value.

          if(CurrentBar < 10)

          With multiple series, its best for a check for each series.

          if (CurrentBars[0] < 10 || CurrentBars[1] < 10)



          Basically, the smaller time frame updates quite a few times before the larger time frame does.
          Attached Files
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Koganam, thanks so much for your feedback.

            Chelsea, also thanks for the further information.

            I've had other things to tend to in the past few days, so it will take me a while to get back up to speed on this. I will post back here as soon as I've had an opportunity to review the further suggestions.

            Again, thanks to everyone.

            Comment


              #7
              I'm making some progress on this but there seems to be something fundamental that is beyond my level of programming experience.

              As an example, I have uploaded an indicator that is supposed to draw a line on the previous day's high on an intraday chart. Instead the indicator is drawing a line on the high from two day's ago -- see attached screenshot.

              Could someone straighten me out on this? What's missing from my code?

              Code:
              [SIZE="2"]	public class PrevHigh : Indicator
              	{
              		private Series<double> myEmptyIndexedSeries;
              		private double PrevDayHigh = 0;
              			
              		protected override void OnStateChange()
              		{
              			if (State == State.SetDefaults)
              			{
              				Description									= @"";
              				Name										= "PrevHigh";
              				Calculate									= Calculate.OnPriceChange;
              				IsOverlay									= true;
              				DisplayInDataBox							= true;
              				DrawOnPricePanel							= true;
              				DrawHorizontalGridLines						= true;
              				DrawVerticalGridLines						= true;
              				PaintPriceMarkers							= true;
              				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
              				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
              				//See Help Guide for additional information.
              				IsSuspendedWhileInactive					= true;
              				BarsRequiredToPlot = 10;
              			}
              			else if (State == State.Configure)
              			{
              				AddDataSeries(BarsPeriodType.Day, 1);
              			}
              			else if (State == State.Historical)
              			{
                    			myEmptyIndexedSeries = new Series<double>(BarsArray[1]);
              			}
              		}
              
              		protected override void OnBarUpdate()
              		{
              			if(CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
              				return;
              			
              			if (BarsInProgress == 1)
              			{
              				PrevDayHigh = Highs[1][1];
              			}
              			
              			if (BarsInProgress == 0)
              			{
              				Draw.Line(this,CurrentBar.ToString()+"PrevHi",false
              					,1,
              					PrevDayHigh
              					,0,
              					PrevDayHigh
              					,Brushes.Goldenrod,DashStyleHelper.Solid,2);
              			}
              		}[/SIZE]
              Attached Files

              Comment


                #8
                Hello h1000,

                Highs[1] refers to the Daily series (AddDataSeries(BarsPeriodType.Day, 1).

                This means a new Daily bar will form each time a session ends.

                If the session has not ended, then there isn't a new bar.

                Thus, Highs[1][0] refers to the most recently closed daily bar which is the previous session.

                Highs[1][1] refers to the bar before the most recently closed daily bar.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by traderqz, Yesterday, 09:06 AM
                3 responses
                21 views
                0 likes
                Last Post NinjaTrader_ThomasC  
                Started by f.saeidi, Today, 10:19 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by kujista, Today, 06:23 AM
                5 responses
                15 views
                0 likes
                Last Post kujista
                by kujista
                 
                Started by traderqz, Today, 12:06 AM
                3 responses
                6 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by RideMe, 04-07-2024, 04:54 PM
                5 responses
                28 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X