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

Close at particular bar

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

    Close at particular bar

    What coding do i need to close either a long or short position at the close of a particular bar such as the 11:00 Am bar?

    #2
    Hi,

    You can use the ToTime() method to compare the time of a bar. See the following Help Guide information.

    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      Hi,

      You can use the ToTime() method to compare the time of a bar. See the following Help Guide information.

      http://www.ninjatrader-support.com/H...V6/ToTime.html

      Tried this code, for closing out at 4:00PM but it doesn't work?

      if (ToTime(Time[0]) == ToTime(16,0,0) )
      {
      ExitLongLimit(Bars.CurrentBid);
      ExitShortLimit(Bars.CurrentAsk);
      }

      Comment


        #4
        Jlm,

        I think you should try

        if (ToTime(Time[0]) >= ToTime(16,0,0) )

        It might be that a tick is received 1 second after 16:00 hours and at that moment barclose is calculated. Time has passed 16:00:00 and the condition is not met.


        Comment


          #5
          This is what I use...

          if (ToTime(Time[0]) >= 150000)) do something...

          Mike

          Comment


            #6
            [quote=ceesvh;16266]Jlm,

            I think you should try

            if (ToTime(Time[0]) >= ToTime(16,0,0) )

            It might be that a tick is received 1 second after 16:00 hours and at that moment barclose is calculated. Time has passed 16:00:00 and the condition is not met.


            That sounds right.
            Will try.
            Thanks

            Comment


              #7
              [quote=Mike Winfrey;16268]This is what I use...

              if (ToTime(Time[0]) >= 150000)) do something...

              Mike



              Sounds good.
              Thanks

              Comment


                #8
                Not sure if I am replying correctly, but thanks for all the help!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Segwin, 05-07-2018, 02:15 PM
                14 responses
                1,789 views
                0 likes
                Last Post aligator  
                Started by Jimmyk, 01-26-2018, 05:19 AM
                6 responses
                837 views
                0 likes
                Last Post emuns
                by emuns
                 
                Started by jxs_xrj, 01-12-2020, 09:49 AM
                6 responses
                3,293 views
                1 like
                Last Post jgualdronc  
                Started by Touch-Ups, Today, 10:36 AM
                0 responses
                13 views
                0 likes
                Last Post Touch-Ups  
                Started by geddyisodin, 04-25-2024, 05:20 AM
                11 responses
                63 views
                0 likes
                Last Post halgo_boulder  
                Working...
                X