Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Yesterday's bar

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

    Yesterday's bar

    Hi all,

    This is an extremely noobish question, but I'm having trouble with DateTime structures in C#.

    Would someone be able to help me with the syntax to get the Close of the 3:30PM bar of the previous day?

    I'm guessing that the method to use is GetBar(), I just don't know how to write it out.

    Thanks in advance!

    -Nick

    #2
    Hi Nick,

    Yes, GetBar() is tool for this. You can build a DateTime object that's for "yesterday at 3:30 PM" using something like this:


    Code:
    DateTime myDateTime       = new DateTime(Time[0].Year, Time[0].Month, Time[0].AddDays(-1).Day, 15, 30, 0); 
    int myBarsAgo = GetBar(myDateTime);
    double myClose	= Close[myBarsAgo];
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      Thanks for your reply.

      I have a private variable that represents the close of the session (3:30pm) that is coded like this:

      private int endTime = 153000;

      How do I use that variable in the DateTime example you provided?
      (i.e. to replace the bold section below:

      DateTime myDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].AddDays(-1).Day, 15, 30, 0);

      Thanks!

      -Nick
      Last edited by nicbizz; 11-01-2011, 05:26 PM.

      Comment


        #4
        ToTime() creates an integer. based only on the time component, with no reference to the date or day. Therefore, you cannot use it for any purpose beyond pure time measurements.

        For what you want to do, you must use the more elaborate C# time structures, as shown in the example given you, albeit it could be written a tad more compactly.

        Comment


          #5
          hi koganam,

          I was wondering if there was a way to reformat the ToTime integer (i.e. 153000) into "15, 30, 0" so I can plug it into the DateTime syntax above.

          Of the top of my head, I figured a int-to-string conversion followed by .Substring() would probably work, but that seems a highly inefficient way to format something so simple.

          Comment


            #6
            ncbizz,

            I am happy to assist you.

            I believe the best way would be to use a string for the time instead.

            i.e. private string "153000"

            Then parse it appropriately. Here is a helpful link : http://stackoverflow.com/questions/4...ividual-digits

            Please let me know if I may assist further.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Adam,

              That's brilliant. Why didn't I think of that lol.

              Thanks!

              -Nick

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              647 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              369 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              572 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              573 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X