Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Open/Close of a bar on another chart?

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

    Open/Close of a bar on another chart?

    Hello,

    Please forgive me if this is documented somewhere - I've looked without success - but if I have a five-minute chart and I want to reference some indicator value on a one-minute chart, I would do this in the strategy:

    Code:
    Add(PeriodType.Minute,  1);     //  BarsArray[1]
    And then do this in the code:

    Code:
    if (  DoubleStochastics (BarsArray[1], 11).K[1] > 90  )
    This works fine.

    But what do I do if I want to reference the Open/High/Low/Close of an actual price bar on that same one-minute chart? In pseudo-code it would be something like Close[0](BarsArray[1] - although that's definitely not right.

    Thanks in advance.

    #2
    Oops, I think I wrote too quickly. I found this quite by accident:

    Comment


      #3
      Hello,

      Open, Low, High, and Close have plural versions which will allow you to specify which data series you wish to reference. Below are a few examples:

      Closes[1][2] -- The close of the secondary data series, two bars ago
      Highs[0][0] -- The high of the primary data series, on the current bar

      You can find more info in our help guide at the links below:
      http://www.ninjatrader.com/support/h...html?opens.htm
      http://www.ninjatrader.com/support/h...html?highs.htm
      http://www.ninjatrader.com/support/h....html?lows.htm
      http://www.ninjatrader.com/support/h...tml?closes.htm

      Please let me know if I can assist further.
      Dave I.NinjaTrader Product Management

      Comment


        #4
        Thanks! When adding the secondary timeframe, does this:

        Code:
        Add(PeriodType.Minute,  1);
        Do the same as this?
        Code:
        Add(Instrument, PeriodType.Minute, 1);

        Comment


          #5
          Can This Code Plot The OHLC of the Last 15 Minute Bar?

          Hi,

          Can this code plot the OHLC of the last 15 Minute Bar on a 3 minute chart?
          I would like to have horizontal lines extend to the right on a 3 minute chart with the previous open high low and close of the last 15 minute bar or candle starting at 5:00 PM CST for the eMini S&P.
          I would then like to buy if the close of the previous 3 minute bar was below the close of the 15 minute bar, and the next 3 minute bar closes above the close of the 15 minute bar.
          The stop would go below the 15 minute bar low.

          Thanks in advance,
          DT_12

          Comment


            #6
            hawks67 -- you are on the right track, but you will need to make one edit. That second constructor overload for Add requires a string for the instrument name. "Instrument" is a class, but "Instrument.Fullname" is a string, so you can pass that in for the instrument name in the call to Add().

            For more information on the properties of the Instrument class, please see the link below:
            http://www.ninjatrader.com/support/h...instrument.htm

            DayTrader -- I will look into your question and get back to you soon. In the meantime, the thread will remain open for others to comment.
            Dave I.NinjaTrader Product Management

            Comment


              #7
              DayTrader, that's exactly right. If you are looking at a 15 minute chart, and you've added a 3-minute data series in your code, then you can detect OHLC values from the 3 minute data series and draw it on your 15 minute chart, or vice versa if you wish to plot longer-timeframe support/resistance on a shorter-timeframe chart.
              Dave I.NinjaTrader Product Management

              Comment


                #8
                Hi Dave, can you demonstrate how to do the indicator please?
                At TradeStation, I would just put the indicator on the second data stream.
                Last edited by DayTrader12; 06-09-2015, 05:14 PM.

                Comment


                  #9
                  You bet -- I've attached a simplified sample. This will show the mechanics of drawing a line based on a secondary data series. In this example, I'm assuming we're looking at a 3 minute chart, and we're looking to draw the line based on the high of a 15 minute bar.
                  Attached Files
                  Dave I.NinjaTrader Product Management

                  Comment


                    #10
                    Hi Dave,
                    Thanks ever so much for the help
                    So, this code puts the high of the previous 15 minute bar as a horizontal line on my 3 minute chart?
                    Then I would use this line: DrawHorizontalLine("line",Highs[1][0],Color.Blue); //Draw a line on the chart based on the high of the 15 minute bar, rather than the 3 minute bars on the chart
                    and change it to this for the low: DrawHorizontalLine("line",Lows[1][0],Color.Green); //Draw a line on the chart based on the low of the 15 minute bar, rather than the 3 minute bars on the chart
                    and this for the close: DrawHorizontalLine("line",Close[1][0],Color.Gold); //Draw a line on the chart based on the close of the 15 minute bar, rather than the 3 minute bars on the chart
                    and this for the open: DrawHorizontalLine("line",Open[1][0],Color.Magenta); //Draw a line on the chart based on the Open of the 15 minute bar, rather than the 3 minute bars on the chart

                    I will try that and see what happens.
                    Thanks again
                    DT_12

                    Comment


                      #11
                      No luck, it only draws the last one, the open on the chart and not the HLC.

                      I see where I had to call the open opens, and the close closes to make it compile.
                      DrawHorizontalLine("line",Highs[1][0],Color.Red); //Draw a line on the chart based on the high of the 15 minute bar, rather than the 3 minute bars on the chart
                      DrawHorizontalLine("line",Lows[1][0],Color.Blue); //Draw a line on the chart based on the low of the 15 minute bar, rather than the 3 minute bars on the chart
                      DrawHorizontalLine("line",Closes[1][0],Color.Gold); //Draw a line on the chart based on the close of the 15 minute bar, rather than the 3 minute bars on the chart
                      DrawHorizontalLine("line",Opens[1][0],Color.Magenta); //Draw a line on the chart based on the open of the 15 minute bar, rather than the 3 minute bars on the chart

                      Can you fix it so it draws the previous 15 minute OHLC on my 3 minute chart and then recalculates when a new 15 minute bar closes?

                      Thanks Dave
                      Last edited by DayTrader12; 06-10-2015, 04:48 PM.

                      Comment


                        #12
                        Good morning Dave,

                        Ok, so I coded each as a separate indicator.
                        Now they plot on the 15 minute chart when I put the indicator on a 15 minute chart, and it looks like they plot on the previous bar OHLC like they are suppose to.
                        But, when I change the chart to a 3 minute chart, they don't plot.


                        A couple of horizontal line questions:
                        How can I change the width of the lines.
                        Can I get the lines to extend to the right only?

                        Thanks for the help,
                        DT_12
                        Last edited by DayTrader12; 06-11-2015, 06:08 AM.

                        Comment


                          #13
                          Hello,

                          In order to draw a line that only extends to the right, you will want to use a Ray instead, by calling DrawRay(). One of the constructor overloads for DrawRay() accepts a "width" parameter, which can be used to set the width of the ray. You can find the full documentation for this method at the link below:

                          http://www.ninjatrader.com/support/h...ml?drawray.htm

                          I'm not certain why the line would not be drawn on a 3-minute chart. If you are basing the drawing on a 3-minute secondary data series added in code, then the lines should be drawn and match up perfectly when looking at a 3 minute chart. I've just mocked this up on my end, and it's working well.

                          I'd like to take a look at your code, if you wouldn't mind, so that I can test the script on my end and see what happens. If that works for you, feel free to email a full export (File > Utilities > Export NinjaScript) to platforumsupport [at] ninjatrader [dot] come, and reference ticket # 1332130.
                          Dave I.NinjaTrader Product Management

                          Comment


                            #14
                            Hi Dave,
                            I sent the code.
                            Thanks for looking at it.
                            DT_12

                            Comment


                              #15
                              Hello,

                              Unfortunately, it doesn't look like the code has come through (unless you've heard back from someone else on the team). Feel free to send it over to me in a private message on the forum, if you can.
                              Dave I.NinjaTrader Product Management

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              599 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              345 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              558 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              558 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X