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

Get PrioDayOHLC (Red One) and print it on RTH chart

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

    #16
    Hello ChelseaB,

    And this AddDataSeries() can be done dynamically? Let's say on my chart I only have one data serie (RTH) and programmatically I get the data from ETH dataseries to get the value and print it on my chart?

    Because the thing is I need the PriorDayOHLC().Close[0] from ETH but the close[0] of RTH, but the close[0] not for the onBarUpdate because it will take the close[0]everytime I want the Close[0] of the last day.

    you got me now?

    Thanks!

    Comment


      #17
      Hello cmtjoancolmenero,

      "And this AddDataSeries() can be done dynamically?"

      AddDataSeries() is not supported to be called dynamically. The values supplied to it must be hard coded, and the method call cannot be dynamically called from conditions.

      From the help guide:
      "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."


      "Because the thing is I need the PriorDayOHLC().Close[0] from ETH but the close[0] of RTH"

      You'll need to hard code adding the ETH series to the script and supply the ETH hours data series as the input series to PriorDayOHLC().
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hello ChelseaB,

        So, what would be the way to for instance print the PriorDayOHLC().Close[0] from ETH to my RTH chart?

        My chart is configured with Equities RTH and I want to get the value of an OHLC but using ETH, so pseudo would be something like :

        PriorDayOHLC(FromETH).Close[0] <-- would print the ETH
        PriorDayOHLC(FromRTH).Close[0] <-- would print the RTH

        But that's pseudo I'd like to knw if is there any way to do so.

        I guess what I can do is add two charts as inputSeries Panel 1 ETH Panel 2 RTH and then the indicator get the input series from ETH and plot it to RTH chart, but the thing is I need one thing from each one, for instance I need an OHLC from ETH and plot it to RTH but then from RTH I'd like to get the High[0] of the last candle

        Maybe I can use "US Equities ETH" with the addSeries in the onConfigure and then programmatically I get from the series 1 the OHLC.Close[0] from that and then print it in the series "US Equities RTH".

        To check if it works I'd like to add two lines :
        1 line on the PriorDayOHLC().Close[0] from ETH to the RTH
        1 line on the PriorDayOHLC().Close[0] from RTH to the RTH

        Any hint of this?
        Last edited by cmtjoancolmenero; 05-07-2024, 01:36 AM.

        Comment


          #19
          Hello cmtjoancolmenero,

          Yes, the script would be adding the ETH series with AddDataSeries which becomes BarsArray[1], while BarsArray[0] is the primary series RTH.

          You can then call the indicator twice and supply BarsArray[0] for the first call and supply BarsArray[1] to the second call.

          PriorDayOHLC(BarsArray[0]).Close[0] // will print the RTH prior close
          PriorDayOHLC(BarsArray[1]).Close[0] // will print the ETH prior close
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hello ChelseaB,

            I'm trying to make it super easy but I'm getting this as NinjaScript Output
            : Error on calling 'OnBarUpdate' method on bar 1: Index was outside the bounds of the array.

            protected override void OnBarUpdate()
            {
            if (CurrentBar == 0)
            return;
            Print(" RTH CLOSE " + PriorDayOHLC(BarsArray[0]).Close[0]); // will print the RTH prior close
            Print(" ETH CLOSE " + PriorDayOHLC(BarsArray[1]).Close[0]); // will print the ETH prior close
            }​

            The thing is I've added manually the series from the Chart, doesn't it work? Do I have to add in the configuration AddSeries? How would be? If I add in configuration the AddSeries it will show a new panel? I just want one panel (the RTH) the other I want to be invisible for the user.

            Comment


              #21
              Hello cmtjoancolmenero,

              You will need to ensure all series have enough bars (not just the series updating OnBarUpdate(), and that you have properly called AddDataSeries() in State.Configure.

              In OnStateChange():
              else if (State == State.Configure)
              {
              AddDataSeries(null, new BarsPeriod() { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "CME US Index Futures ETH");
              }

              In OnBarUpdate():
              if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
              return;

              if (BarsInProgress == 0)
              {
              Print(Time[0].ToString() + " RTH CLOSE " + PriorDayOHLC(BarsArray[0]).Close[0]); // will print the RTH prior close
              }
              else if (BarsInProgress == 1)
              {
              Print(Time[0].ToString() + " ETH CLOSE " + PriorDayOHLC(BarsArray[1]).Close[0]); // will print the ETH prior close
              }
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hello ChelseaB,

                it does print the ETH and RTH, but when I try to assign this value to a variable it says

                Indicator 'MyExample': Error on calling 'OnBarUpdate' method on bar 194: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                What I've tried is :

                private double rthClose = 0.0, ethClose = 0.0;

                protected override onBarUpdate()
                {
                if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
                return;

                if (BarsInProgress == 0)
                {
                rthClose = PriorDayOHLC(BarsArray[0]).Close[0]; // will print the RTH prior close
                }
                else if (BarsInProgress == 1)
                {
                ethClose = PriorDayOHLC(BarsArray[1]).Close[0]; // will print the ETH prior close
                }

                ---- My rest of the code ---

                But is throwing me this error, and I don't know why.​

                Comment


                  #23
                  Hello cmtjoancolmenero,

                  Is the error in the rest of your code?

                  If you add a return after the if statements does the error still occur?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hello ChelseaB,

                    Yes it's on my code, but what I want is these two values so I can start do something like drawing a line or whatever, and I guess is this what it's not working.

                    What I wanted to do is :

                    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
                    return;

                    if (BarsInProgress == 0)
                    {
                    rthClose = PriorDayOHLC(BarsArray[0]).Close[0]; // will print the RTH prior close
                    }
                    else if (BarsInProgress == 1)
                    {
                    ethClose = PriorDayOHLC(BarsArray[1]).Close[0]; // will print the ETH prior close
                    }​

                    //Here start doing my stuff like
                    draw a line from rthClose to ethClose
                    Then check stuff about CurrentBar (but from the BarsArray[0]) I don't know if I need to specify everywhere that I want to get the data from BarsArray[0]

                    Comment


                      #25
                      Hello cmtjoancolmenero,

                      The ChartBars are the RTH bars correct?

                      Drawing objects can only be drawn over the primary chart bars. So you wouldn't be able to draw a line from the from the RTH close to the ETH close because the bars after the RTH close would not be on the chart.

                      If the chart bars were the ETH bars and the added series is RTH, you could draw a line from the RTH bars trading day end to the ETH bars trading day end because the bars would be on the chart to drawn on.

                      That said, I've tested the code in your post and I'm seeing its working without any errors appearing. Likely the error is coming from code you have not included in your post.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Hello ChelseaB,

                        yes I think I've fixed it it was a missunderstanding the problem was using a different Trading Hours.

                        Just to clarify if I just want to get the Low and High from the main (RTH) I need to use Higs[0][0], right?
                        Last edited by cmtjoancolmenero; 05-08-2024, 07:09 AM.

                        Comment


                          #27
                          Hello cmtjoancolmenero,

                          Highs[0][0] would be the high of the primary series (the chart bars).
                          Highs[1][0] would be the high of the series added with AddDataSeries().

                          Highs[barsInProgressIndex][barsAgoIndex]
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Matt Skinner, Today, 01:55 AM
                          6 responses
                          29 views
                          0 likes
                          Last Post Matt Skinner  
                          Started by webus, Today, 06:17 AM
                          7 responses
                          19 views
                          0 likes
                          Last Post webus
                          by webus
                           
                          Started by kalli44100, 06-17-2024, 08:57 AM
                          13 responses
                          40 views
                          0 likes
                          Last Post kalli44100  
                          Started by WHICKED, 06-27-2023, 12:07 PM
                          73 responses
                          820 views
                          1 like
                          Last Post NinjaTrader_ChelseaB  
                          Started by PaulMohn, 04-30-2024, 01:45 PM
                          6 responses
                          27 views
                          0 likes
                          Last Post PaulMohn  
                          Working...
                          X