Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get barIndex by time

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

    Get barIndex by time

    Hello,

    There's a few ways you can get time by x, but is there a method to get a specific barIndex for a specific time? For exemple, for 9:30 it returns bar 989.

    Frank
    ty

    #2
    Hello frankduc,

    Thanks for your post.

    Yes, please see the help guide, here: https://ninjatrader.com/support/help...t8/?getbar.htm

    Comment


      #3
      Paul,

      I would like to create an anchor time in the proprieties parameter.

      Is it possible to create a bolean in if (State == State.SetDefaults)
      Something like DateTime = timeValue.ToString("yyyy-MM-dd H:mm:ss") well its not logical beacause its a type but is there a way i can do that?

      This way i could choose a date and time in the parameters and send it to my variable for my indicator.

      Thanks

      Comment


        #4
        Hello frankduc,

        Thanks for your reply.

        In State.SetDefaults, the purpose of the state is to set the default parameters.

        You would use a public input to override the default value.

        Please see the help guide for state clarifications: https://ninjatrader.com/support/help...tatechange.htm

        If you want a property to set both a date and a time:

        [NinjaScriptProperty]
        [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")]
        [Display(Name="MyDateTime")]
        public DateTime MyDateTime { get; set; }

        Comment


          #5
          Hi,

          I tried in
          State.SetDefaults:

          MyDateTime = new DateTime(2020, 2, 10, 7, 47, 0);

          I suppose by that:

          [NinjaScriptProperty]
          [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")]
          [Display(Name="MyDateTime")]
          public DateTime MyDateTime { get; set; }

          That part was going to region proprieties?

          I get this error:

          NinjaScript File Error Code Line Column
          CMAtest1.cs No overload for the 'CMA01' method takes arguments 1 CS1501 74 24

          Comment


            #6
            Hello frankduc,

            Thanks for your reply.

            Correct, the the code [NinjascriptProperty] and below would be outside of OnStateChange() and outside of OnBarUpdate() and typically would be found below OnBarUpdate().

            Comment


              #7
              Hi,

              Does it need #region Properties and #endregion at the end?

              [NinjaScriptProperty]
              [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")]
              [Display(Name="MyDateTime")]
              public DateTime MyDateTime { get; set; }


              I still get this error:
              NinjaScript File Error Code Line Column
              CMAtest1.cs No overload for the 'CMA01' method takes arguments 1 CS1501 74 24

              Comment


                #8
                Hello frankduc,

                Thanks for your reply.

                The #region Properties and #endregion are not needed and they are there to provide the ability to collapse a section of code so that you can visually skip over a section if you are not working in that section. Large code files typically would have a number of regions and you are welcome to add more to your code if it help you visually. Refrence: https://docs.microsoft.com/en-us/dot...ocessor-region

                You can use an internet search for what the error code CS1501 means. In this case we do have a reference in the help guide but in case we do not (we only have a limited set) use the internet. Here is a link to the help guide on error code CS1501: https://ninjatrader.com/support/help...t8/?cs1501.htm

                The Line and column number of the error are Line 74 at column 24 so the compiler has identified for you where to look in the file CMAtest1 to find the error.

                Comment

                Latest Posts

                Collapse

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