Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 Bar Times

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

    NT8 Bar Times

    Paul H put out a great Indicator that measures a bar's time from Open to Close.
    I want to modify it just a little by being able to paint the times a different color if the bar time is below a certain threshold.
    So if I put the threshold at, say 5 seconds, then the indicator plots a Red Bar in the Indicator panel.
    Otherwise, it plots a SeaGreen above 5 seconds.
    How would I add that Condition and Action?
    Attached Files

    #2
    Hello RJBen,

    Below is a link to the original indicator I think you are referring to.
    BarTimes is a simple indicator to provide the time it takes to build a bar This is useful for non time-based bars such as Range, Renko, Volume, Tick, etc, to help show how long any bar took to develop. The indicator has options to display the time in milliseconds, seconds, minutes, or hours, the default […]


    The BarTime[0] plot series is holding the calculated value for the time.

    From your own custom indicator you could call this indicator and check the BarTimes(CustomBsEnumNamespace.TimeSelector.Second s).BarTime[0] value for your own conditions.

    You could also copy the original script with a new unique name and modify the copy to add your conditions.

    Compare BarTime[0] as a number of seconds.

    Assign BarBrush a Brush value to change the color of the bar.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    For example:
    Code:
    if (BarTimes(CustomBsEnumNamespace.TimeSelector.Seconds).BarTime[0] > 5)
    {
    BarBrush = Brushes.Red;
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea I removed the timeframes I won't need- milliseconds, minutes and hours.
      I tried adding the code in several places:
      if (BarTimes(CustomBsEnumNamespace.TimeSelector.Secon ds).BarTime[0] > 5)
      {
      BarBrush = Brushes.Red;
      }

      It says I "Cannot implicitly convert type 'CustomBsEnumNamespace.TimeSelector' to 'bool'
      It also says "No enclosing loop out of which to break or continue"
      Where should this go?

      protected override void OnBarUpdate()
      {
      if (CurrentBar < 1)
      return;

      if (Bars.IsFirstBarOfSession)
      {
      if (IsFirstTickOfBar)
      {
      temp = Time[0];
      }
      else
      {
      if (CustomBsEnumNamespace.TimeSelector.Seconds);
      {
      BarTime[0] = (Time[0] - temp).TotalSeconds;
      break;
      }
      }
      }

      else
      {
      if (CustomBsEnumNamespace.TimeSelector.Seconds);
      {
      BarTime[0] = (Time[0] - Time[1]).TotalSeconds;
      break;
      }
      }
      }

      Comment


        #4
        Hello RJBen,

        You have:
        if (CustomBsEnumNamespace.TimeSelector.Seconds);

        This doesn't have any comparison, doesn't call the BarTimes() indicator, and has a semicolon after it for 'no operation'.

        You are comparing an enum to be true or false which isn't valid C#.

        Try the suggested branching command instead:
        Code:
        if (BarTimes(CustomBsEnumNamespace.TimeSelector.Seconds).BarTime[0] > 5)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          It says, "Non-invocable member 'rbBarTimes.BarTime' cannot be used like a method"

          Comment


            #6
            Hello RJBen,

            What is rbBarTimes?

            Is this a variable holding the indicator?

            Are you trying to access a specific bar in a series with an index?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I renamed it trying to customize it.
              This is what I have:
              Attached Files

              Comment


                #8
                Hello RJBen,

                To confirm, you no longer using the original indicator and you are now using your own custom indicator?

                And to confirm, you are getting the same exact error message when compiling? ("Non-invocable member 'rbBarTimes.BarTime' cannot be used like a method")
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I deleted the timeframes I won't be using. I kept the "seconds" I renamed it rbBarTimes
                  The message reads "Argument 1: cannot convert from 'CustomBsEnumNamespace.TimeSelector' to 'NinjaTrader.NinjaScript.ISeries<double>'

                  Comment


                    #10
                    Hello RJBen,

                    To confirm, you are no longer getting the error ""Cannot implicitly convert type 'CustomBsEnumNamespace.TimeSelector' to 'bool'"?

                    Further, the code you posted in post # 7 is the same code you are using now?

                    May I have a screenshot of the NinjaScript Editor showing the entire window including the error message and line of affected code to confirm?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      This what it shows.
                      Attached Files

                      Comment


                        #12
                        Ya know what- forget it. This is way, way, way too complicated. When I closed the program and reopened it- this code has 150 errors on it now.
                        Last edited by RJBen; 02-03-2025, 05:09 PM.

                        Comment


                          #13
                          Hello RJBen,

                          The issue appears to be a coding error in the BarTimes indicator. The TimeUnits input was missing the [NinjaScriptProperty] attribute.

                          I've corrected and attached is a test script using the suggested code.
                          RJBenBarTimesTest_NT8.zip
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            It still doesn't work. Imports fine but added to a small time frame it doesn't draw any bars in the indicator panel. That's okay my friend- I'll use the original. Just wanted to make it a kind of Pace of the Tape Indicator. I'll just draw a horizontal Line on the Original. If it's below that Horizontal Line set to 5 seconds then the bar is Opening and Closing in 5 seconds. The Red bar would just make it a little easier. Thanks Chelsea!!

                            Comment


                              #15
                              Hello RJBen,

                              The test script is not designed to draw any rectangles. It sets the BarBrush to change the color of the bar to red. It also prints to the output window.

                              This was intended to show you the suggested code can compile.

                              I may have misunderstood your initial inquiry.

                              "I want to modify it just a little by being able to paint the times a different color if the bar time is below a certain threshold."

                              Are you not wanting to change the color of the bar?
                              Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                              Are you trying to set a plot value with bars plot style?


                              Are you wanting to call Draw.HorizontalLine() to draw a horizontal line?
                              Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                              Are you wanting to call Draw.Rectangle() to draw a rectangle over a few bars?
                              Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

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