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 Leeroy_Jenkins, Today, 03:45 AM
            0 responses
            13 views
            0 likes
            Last Post Leeroy_Jenkins  
            Started by sinpeople, Today, 04:38 AM
            0 responses
            10 views
            0 likes
            Last Post sinpeople  
            Started by Futurestrader00, Yesterday, 06:14 PM
            1 response
            17 views
            0 likes
            Last Post cincai
            by cincai
             
            Started by ballston, Today, 06:32 AM
            0 responses
            4 views
            0 likes
            Last Post ballston  
            Started by Danila, Today, 04:38 AM
            2 responses
            7 views
            0 likes
            Last Post Danila
            by Danila
             
            Working...
            X