Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get the price at specific time

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

    Get the price at specific time

    Hi,
    If I need the price exactly at 9:00 AM everyday what will be the code. There is code below that you need to specify exact date. But I need that price in the indie everyday without changing the date. Can someone please specify the code for it.

    Examples
    // Check that its past 9:45 AM
    if (ToTime(Time[0]) >= ToTime(9, 45, 00))
    {
    // Calculate the bars ago value for the 9 AM bar for the current day
    int barsAgo = CurrentBar - Bars.GetBar(new DateTime(2006, 12, 18, 9, 0, 0));

    // Print out the 9 AM bar closing price
    Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
    }

    Thanks in advance

    #2
    Originally posted by billsingh View Post
    Hi,
    If I need the price exactly at 9:00 AM everyday what will be the code. There is code below that you need to specify exact date. But I need that price in the indie everyday without changing the date. Can someone please specify the code for it.

    Examples
    // Check that its past 9:45 AM
    if (ToTime(Time[0]) >= ToTime(9, 45, 00))
    {
    // Calculate the bars ago value for the 9 AM bar for the current day
    int barsAgo = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 0, 0));

    // Print out the 9 AM bar closing price
    Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
    }

    Thanks in advance
    Corrected inside your original text.

    ref: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Comment


      #3
      Thank you koganam. I will try and let you know if I need more help.

      Comment


        #4
        Hi koganam,
        it has been executing every bar and bring different prices. How can I just have it execute at 9:05 and bring just one price that was at 9:00AM.

        Comment


          #5
          Originally posted by billsingh View Post
          Hi koganam,
          it has been executing every bar and bring different prices. How can I just have it execute at 9:05 and bring just one price that was at 9:00AM.
          It is doing what you asked it to do. You say it should run if the time is past 0945 hrs. If you want it to run in a shorter time window, then you have to constrain it to run in a smaller window. If you are using fixed-time bars, you can specify an exact time. Otherwise specify a reasonable time window for the instrument where you are going to be using the indicator.

          Comment


            #6
            Originally posted by koganam View Post
            It is doing what you asked it to do. You say it should run if the time is past 0945 hrs. If you want it to run in a shorter time window, then you have to constrain it to run in a smaller window. If you are using fixed-time bars, you can specify an exact time. Otherwise specify a reasonable time window for the instrument where you are going to be using the indicator.
            Thank you Koganam, I will specify = instead of >= .

            Really appreciate your help.
            Bill

            Comment

            Latest Posts

            Collapse

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