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

Time taken for each bar

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

    Time taken for each bar

    Hey guys,

    Can someone point me in the right direction for making a histogram indicator(like Volume etc.) that displays how long each bar/candle has taken to form? I'm using volume based charts but still want to see how LONG each candle has taken to get to the volume that the chart is set at.

    Thanks!!

    #2
    Hello Jumper,

    Thanks for your post.

    To plot the results as a histogram, when you define the plot, use PlotStyle.Bar. Here is an example:

    AddPlot(new Stroke(Brushes.OrangeRed, 2), PlotStyle.Bar, "BarTimes");

    Reference: http://ninjatrader.com/support/helpG...s/?addplot.htm

    Bars in NinjaTrader have a time stamp based on the end of the bar. To calculate the bar time, you can subtract the previous bar close time from the current bars close time. You can output the time value in any number of ways (milliseconds, seconds, minutes, hours, etc.etc.). Here is an example of calculating the time between two bars and outputting the total seconds to the plot BarTimes:

    BarTimes[0] = (Time[0] - Time[1]).TotalSeconds; // calculate total second for bar duration.

    Reference: http://ninjatrader.com/support/helpG...eries_time.htm
    Gets the value of the current TimeSpan structure expressed in whole and fractional seconds.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply.

      I have added the AddPlot in the if ( State == State.SetDefaults) block and then added the BarTimes calculation in the OnBarUpdate() section, bu it's not compiling, saying "Cannot apply indexing with [] to an expression of type 'method group'."

      Have I put the code in the right areas?

      Thanks!

      Comment


        #4
        Hello Jumper,

        Thanks for your reply.

        Your description sounds correct in terms of code placement. If you copied my example and used "BarTimes" as the name of the plot, make sure that the OnBarUpdate code also uses BarTimes. If you were to use BarTime (which is another indicator name), that would generate that error.

        Please note that you will also need to check that you have enough bars loaded before accessing the line: Time[0] - Time[1]. On the first bar loaded there would not be a [1] and this would cause a bar indexing error. To prevent this, before the code line and in OnBarUpdate(), use: if (CurrentBar < 1) return;
        Reference: http://ninjatrader.com/support/helpG...currentbar.htm

        I've attached a screenshot of what I tested here.
        Attached Files
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi, thanks again for the answer.

          Still not getting the same as you. I don't have the Properties #region down the bottom like you do, weird. The rest of my code is exactly the same, so I added the #region manually but now I'm getting "BarTimes': member names cannot be the same as their enclosing type" error upon compiling. I just made a custom indicator, named it then clicked "Generate" immediately after giving it the name "BarTimes" to get to where I am now.

          thanks

          Comment


            #6
            Hello Jumper,

            Thanks for your reply.

            Please post your source code (.cs) file and I can take a look.
            Attach the file which can be found in Documents>NinjaTrader8>bin>Custom>Indicators>
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi,
              Is the BarTimer indicator for NT 8 which Ninjatrader_Paul displayed available for download anywhere?



              Thank you.

              Comment


                #8
                Hello bob77713,

                Thanks for your post.

                The indicator was not previously provided as it was shown as an example to help the original thread posted and as they were working in Ninjascript a simple example was all that was needed. I'd since deleted the example but it is simple enough to recreate and have attached for your convenience.
                Attached Files
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Paul for providing indicator!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by tsantospinto, 04-12-2024, 07:04 PM
                  6 responses
                  98 views
                  0 likes
                  Last Post tsantospinto  
                  Started by rocketman7, Today, 02:12 AM
                  5 responses
                  26 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by ZenCortexReal, Today, 08:54 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post ZenCortexReal  
                  Started by ZenCortexReal, Today, 08:52 AM
                  0 responses
                  0 views
                  0 likes
                  Last Post ZenCortexReal  
                  Started by trilliantrader, 04-18-2024, 08:16 AM
                  7 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X