Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

VWAP Modification

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

    #16
    Thanks

    Time[highestBarsAgo]; will NOT compile error CS0201 - i have this in the OnBarUpdate area - is that where it goes or in State.Configure

    I do not really follow this
    Therefore the bar index would be CurrentBar - HighestBar().

    HighestBar() from what time frame - I am looking for highestbar of last 78 bars of a dataseries, that dataseries could be a 30 minute bar and that would be 6 days of 30 charts

    so I am using startBarIndexmaxHigh1 ie named maxHigh1 to reference the HighestBar of dataseries Closes[1]

    startBarIndexmaxHigh1 = Bars.GetBar( highestBarsAgo );// from the Time[highestBarsAgo]

    or

    startBarIndexmaxHigh1 = ( CurrentBar - HighestBar() ); // again how does this identify with the correct dataseries HighestBar(Highs[1], 78);

    Thanks again
    ​​
    Last edited by DTSSTS; 04-20-2023, 07:36 AM.

    Comment


      #17
      Hello DTSSTS,

      Thanks for your note.

      HighestBar() should not be used in State.Configure(). This method should be used in OnBarUpdate(). State.Configure() is not guaranteed to have all data series loaded and should only be used to add additional data series via AddDataSeries(), declare custom resources, and override and configure values set by the UI.

      Since you need to have all data series loaded before calling HighestBar() this method should not be used in State.Configure().

      See this help guide page about NinjaScript states: https://ninjatrader.com/support/help...tatechange.htm

      Further, how are you calling Time[highestBarsAgo] in your script? Is this being used in a condition or being assigned to a DateTime variable?

      Only calling Time[highestBarsAgo]; would result in that compile error. This value should either be used in a condition or assigned to a DateTime variable since Time[] returns a DateTime value as noted in the help guide. For example:

      DateTime myTime = Time[highestBarsAgo];

      A bar index is not the same as a bars ago. A bar index is the number of the bar on the chart. A bars ago is the number of bars back from the current bar on the chart.

      HighestBar() returns a bars ago value, not a bar index value. If HighestBar() returns a value of 5 and say the CurrentBar on the chart is bar 100, this means that the bar with the highest price detected by HighestBar() has a bar index of 95.

      CurrentBar (100) - HighestBar() (5 bars ago) = 95 bar index. (100 - 5 = 95)

      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #18
        Starting at the Bottom item

        HighestBar() returns a bars ago value, not a bar index value. If HighestBar() returns a value of 5 and say the CurrentBar on the chart is bar 100, this means that the bar with the highest price detected by HighestBar() has a bar index of 95.

        CurrentBar (100) - HighestBar() (5 bars ago) = 95 bar index. (100 - 5 = 95)

        I DO NOT UNDERSTAND HOW IT KNOWS BAR 95 FOR EXAMPLE IS BAR FROM DATASERIES CLOSES[1] OR CLOSES[2]

        ​I HAVE THIS int highestBarsAgo = HighestBar(Highs[1], 78); in the conditions area of OnBarUpdate // is that correct placement

        Also can I name this int highs1BarsAgo = HighestBar(Highs[1], 78);

        I DO NOT KNOW WHERE THIS GOES or the syntax for it: CurrentBar - HighestBar()

        NEXT do i need this in the State.Configure area

        startBarIndex = CurrentBar - HighestBar(); // OR DO I EVEN NEED THIS AT ALL // it does not compile either

        NEXT i am lost on the time part, when I tried various incorrect syntax I did get log errors on calling OnStateChange

        I do have all the dataseries added in the State.Confingure area as I normally do in other applications ie stratgies

        i have looked at the time help

        Time[highestBarsAgo] in your script? Is this being used in a condition or being assigned to a DateTime variable?

        I tryed Times[highestBarsAgo]; in both the configure area and in the condition are - I think it would be best to use in the OnBarUpdate section as a condition as keeping the conditions for each datasereis ie Closes[1] Closes[2] etc would all be together generally

        IS THIS A CONDITION SYNTAX DateTime myTime = Time[highestBarsAgo];

        THANKS​

        what is this suppose to print

        Print("HighestBar: " + HighestBar(Highs[1], 78));

        it is printing the highest bar number of the primary, not the Secondary Data
        Last edited by DTSSTS; 04-20-2023, 10:33 AM.

        Comment


          #19
          Hello DTSSTS,

          Thanks for your note.

          "I DO NOT UNDERSTAND HOW IT KNOWS BAR 95 FOR EXAMPLE IS BAR FROM DATASERIES CLOSES[1] OR CLOSES[2]"

          In that specific example, CurrentBar refers to the primary series bar. The close price of the primary series would be Closes[0].

          If you want to reference the first added secondary series bars object in a script, CurrentBars[1][0] would be used.

          CurrentBars[1][0] would get the current bar on the first added secondary bars object. The close price of the first added secondary series would be Closes[1].

          CurrentBars[2][0] would get the current bar on the second added secondary bars object. The close price of the second added secondary series would be Closes[2].

          See the help guide pages below for more information about CurrentBar and CurrentBars.

          CurrentBar: https://ninjatrader.com/support/help...currentbar.htm
          CurrentBars: https://ninjatrader.com/support/help...urrentbars.htm

          It is important to review this help guide page for details on how to multi-timeframe/multi-instrument NinjaScripts function and how to access values from the primary series or secondary bar series: https://ninjatrader.com/support/help...nstruments.htm

          "​I HAVE THIS int highestBarsAgo = HighestBar(Highs[1], 78); in the conditions area of OnBarUpdate // is that correct placement"

          Yes, this can be placed in OnBarUpdate().

          "Also can I name this int highs1BarsAgo = HighestBar(Highs[1], 78);"

          Yes, instead of naming the int variable highestBarsAgo you could name it highs1BarsAgo.

          "I DO NOT KNOW WHERE THIS GOES or the syntax for it: CurrentBar - HighestBar()"

          I was explaining that the code you shared from the other author in post # 14 gets a time (anchorDateTime) and then gets a bar index at that time (Bars.GetBar(anchorDateTime )).

          "CurrentBar - HighestBar()" was a very simple example that was used to explain the difference between a bar index and a bars ago value and how you could get a bar index value using HighestBar() if you needed to.

          Since you are assigning HighestBar() to highs1BarsAgo, this would look like CurrentBar - highs1BarsAgo. If you are wanting to get the bar index value of the first added secondary series in your script, the syntax would look like CurrentBars[1][0] - highs1BarsAgo. For more information about bar index vs. bars ago, see post # 17.

          "startBarIndex = CurrentBar - HighestBar(); // OR DO I EVEN NEED THIS AT ALL // it does not compile either"

          If you are specifically calling this line of code in your script it would result in a compile error since you are not supplying any arguments into the HighestBar() method. You would need to supply arguments (a Series and a period) to this method when calling it. The arguments are noted in the help guide, HighestBar(ISeries<double> series, int period).

          HighestBar(): https://ninjatrader.com/support/help...highestbar.htm

          Note that the HighestBar() method should not be used in State.Configure() since not all data series are loaded during this State. You could try using this method in State.DataLoaded or in OnBarUpdate.

          Note that this line of code will get the primary series bar index value that the highest price was found. See above about getting the bar index of added secondary series in the script. If you do not need to use a bar index value in your custom logic then you would not need this line of code. If you do need to use a bar index value in your custom logic then you could use this code to get that bar index value.

          "I do have all the dataseries added in the State.Confingure area as I normally do in other applications ie stratgies"

          This is correct. Additional data series should be added to the script in State.Configure(). This is where additional data series should be added but it does not mean that all data series are loaded. State.Configure() is called after a user adds an object to the applied list of objects and presses the OK or Apply button. This state is called only once for the life of the object. State.DataLoaded() is called only once after all data series have been loaded.

          Review this help guide page about NinjaScript States in OnStateChange() to see the differences: https://ninjatrader.com/support/help...tatechange.htm

          "Time[highestBarsAgo] in your script? Is this being used in a condition or being assigned to a DateTime variable?"

          Time[highestBarsAgo] was simply showing how you could pass in highestBarsAgo as the barsAgo argument for Time[barsAgo]. You would have to either assign this value to a class-level DateTime variable or use it in a condition depending on your use case.

          "IS THIS A CONDITION SYNTAX DateTime myTime = Time[highestBarsAgo];​"

          This is not a condition. This syntax would be assigning the Time[highestBarsAgo] value to a DateTime variable called 'myTime'. The myTime variable could then be used later in the script if needed.

          To truly know how the script is functioning it would be necessary to use prints and debug by looking at all of the information the script is using for decisions.

          Below is a link to a forum post that demonstrates how to use prints to understand behavior.
          https://ninjatrader.com/support/foru...121#post791121

          In the support department at NinjaTrader, it is against our policy to create, debug, or modify, code or logic for our clients. It will ultimately be up to you to come up with the custom logic on your script to accomplish your specific goals.

          In the Support department, we are able to provide simple example code snippets, attach example scripts and link to samples on the forum, and provide educational resources from the help guide.

          You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. If you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request you could write in to vendorsupport[at]ninjatrader[dot]com.
          Last edited by NinjaTrader_BrandonH; 04-20-2023, 10:40 AM.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #20

            ok I figured we were headed here CurrentBars[1][0] - ( highs1BarsAgo );

            all below in the OnBarUpdate area



            int highs1BarsAgo = HighestBar(Highs[1], 78);

            double high1Price = High[highs1BarsAgo];// is this needed?

            DateTime myhigh1Time = Times[highs1BarsAgo];

            CurrentBars[1][0] - ( highs1BarsAgo ); or this CurrentBars[1][0] - highs1BarsAgo; // of course this does not compile

            I STILL DO NOT KNOW HOW TO COMPLETE THIS LINE OF CODE OR WHERE TO PUT IT


            DO I NEED SOMETHING LIKE THIS

            DateTime myhigh1Time;

            myhigh1Time = Time[highs1BarsAgo];

            high1Price = Bars.GetBar(CurrentBars[1][0] - highs1BarsAgo );​


            thanks again

            Comment


              #21
              i approach some different conditions and I have ran into this

              Indicator 'ATSAnchoredHighvwap': Error on calling 'OnBarUpdate' method on bar 1214: Index was outside the bounds of the array.


              Something I have not ran across before, this is on a minute chart type
              At first I thought was not enough bars but more days of data dones not change it, Also thought could be first bar of data but more days again confirms it is not because the bar number remains 1214

              this is on a 2 minute chart, If i change to a 1 minute chart then the bar number is 2429, if I change to a 5 minute chart then is 485 bar number

              So this is a particualar place in time

              Which I believe indicates I am findiing or at least looking for an actaully anchor bar, I would be that each of those bars is a High bar

              the code is running as the Prints output prints the HighestBar, the the error occurs at the bar number

              When I changed the secondary dataseries from 2 minute bars to a 4 minute bar I expected the bar number to change BUT it did not

              SO I AM STARTING TO THINK that is might be a glich in the data itselt at that point in time rather than the code

              FURTHUR test I change to RTH chart and 5 minutes 3 day loaded - NO error (no plots but I think that is something different)

              Continue changing days with no error until I reached enough days to reach bar number 485 and Error returns

              Any Thoughts

              ​I removed the newer logic and the error went away, so was the logic looking for the anchor bar
              tried some Chat GBT logic

              Still stuck at post 20
              Last edited by DTSSTS; 04-21-2023, 11:58 AM.

              Comment


                #22
                Overcame the Time Date with Bing Chat AI

                Last edited by DTSSTS; 04-22-2023, 12:18 PM.

                Comment


                  #23
                  I have search forum and help endlessly for this

                  Is there a way to add a display text into that data box. I see how to add as a plot, but the overlay on the chart is the issue with that.

                  So if manually could tell 1 plot only to NOT Overlay would work too

                  Thanks

                  I found this but the pages are now gone



                  Last edited by DTSSTS; 04-23-2023, 02:54 PM.

                  Comment


                    #24
                    If you don't want to see the plot but want the number to appear in the data box, you could set the plot's color to transparent (so the plot itself is invisible), then do ShowTransparentPlotsInDataBox = true; See: https://ninjatrader.com/support/help...sindatabox.htm
                    Bruce DeVault
                    QuantKey Trading Vendor Services
                    NinjaTrader Ecosystem Vendor - QuantKey

                    Comment


                      #25
                      You might also be interesting in PlotStyle.PriceBox which just puts a price box on the chart without any line.
                      Bruce DeVault
                      QuantKey Trading Vendor Services
                      NinjaTrader Ecosystem Vendor - QuantKey

                      Comment


                        #26
                        Hello DTSSTS,

                        Thanks for your notes.

                        QuantKey_Bruce is correct in stating that you could set the plot's brush color to transparent and set ShowTransparentPlotsInDataBox to true if you want it to appear in the Data Box but not on the chart window.

                        ShowTransparentPlotsInDataBox property: https://ninjatrader.com/support/help...ansparentplots indatabox.htm

                        Note that indicators can only plot and do custom rendering in one panel determined by IsOverlay. There are no supported methods to have the indicator plot on the price panel and have the second plot in the indicator on a separate panel.

                        IsOverlay - https://ninjatrader.com/support/help.../isoverlay.htm
                        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                        Comment


                          #27
                          yes was just typing Thanks that is it. I had read that earlier and tried, but I did not realize I had to reload the indicator on the chart to test. Then I removed it and did NOT try again.

                          Thanks again it is perfect

                          Comment


                            #28
                            Continuing with the first modification and referring to the original calculation of standard vwap has set condition to start calculation at

                            if (Bars.IsFirstBarOfSession) // First of bar of Session. which when plotting Overnight session of futures is starting at 6:01 PM which i like for the Other plots

                            BUT if i wish to have the standard vwap start at the first bar of RTH regular trading hours HOW CAN I DEFINE THAT FOR JUST THIS PART


                            ​So we are on a Overnight session but we want if (Bars.IsFirstBarOfSession) to be starting at RTH

                            Thanks for any help

                            Think could be Time of bar at 9:31 am

                            Comment


                              #29
                              Hello DTSSTS,

                              Thanks for your note.

                              You could try adding an additional data series to the script using the AddDataSeries() method syntax that allows you to specify a trading hours template for the instrument you are adding.

                              AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)

                              AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

                              Then, you could do your Bars.IsFirstBarOfSession logic inside the BarsInProgress index of the added series. For example, say the added secondary series is the first added series in the script. The code might look something like this:

                              Code:
                              if (BarsInProgress == 1)
                              {
                                  if (Bars.IsFirstBarOfSession)
                                  {
                                      //place your logic here
                                  }
                              }
                              BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm
                              Last edited by NinjaTrader_BrandonH; 04-24-2023, 11:04 AM.
                              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                              Comment


                                #30
                                Regarding the Transparent Plot

                                AddPlot(Brushes.Transparent, "Anchor ONE Minutes");

                                IS THERE A WAY TO lock the Transparent to keep users from changing the color of the Plot

                                ***************************

                                AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)

                                this particular plot is the only one actually using the primary, but I could change both plots (ie the full sesssion Standard VWAP and the RTH session plot standard vwap)

                                the instrument name would be the primary, so I do not want to specify the Instrument

                                I am using this for my other secondary

                                AddDataSeries(Data.BarsPeriodType.Minute, 5);/// Closes[1]

                                SO

                                AddDataSeries(Data.BarsPeriodType.Minute, 1, WHATGOESHERE );/// Closes different of course

                                ON THE LINK provided I do not see how to input the tradingHoursName

                                I use 3 trading hours

                                US Equities Regular Trading Hours RTH <---- I use this for futures too
                                US Extemded Tradomg Hours ETH (rarely)

                                and <Use instrument settings> (mainly for futures)

                                SO WHAT IS THE TRADING HOURS NAME for those

                                ************************************************** ************

                                regarding if (BarsInProgress == 1)

                                from what I understand the 1 ie refers to Closes[1]

                                if (BarsInProgress == 2) ie refers to Closes[2] /// etc

                                I CURRENTLY DO NOT HAVE if (BarsInProgress == 1) anywhere in any codes I have ever written, so I need to use this I am sure

                                in the case of this indicator I have been starting with chelsea startlogic after this

                                if (HighestBar(Highs[1], AnchorONELookBackPeriod) == 0)

                                SO WOULD THIS BE WHERE I SHOULD ADD

                                /// Closes[1]
                                if ((HighestBar(Highs[1], 78) == 0)
                                && (BarsInProgress == 1))

                                // Closes[2]
                                if ((HighestBar(Highs[2], 78) == 0)
                                && (BarsInProgress == 2))

                                IS THE CORRECT

                                THANKS AGAIN​

                                ************************************************** ****

                                just fwiw, the links you guys are using render a page not found I have found this on many post



                                YOUR link and others are adding %E2%80%8B/ which renders page not found

                                Comment

                                Latest Posts

                                Collapse

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