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 pilotfo, Today, 12:50 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by DTSSTS, Today, 11:35 AM
            2 responses
            10 views
            0 likes
            Last Post DTSSTS
            by DTSSTS
             
            Started by sinpeople, Today, 07:20 AM
            2 responses
            6 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Frank1000, Today, 03:05 AM
            5 responses
            15 views
            0 likes
            Last Post Frank1000  
            Started by fscabrera03, Yesterday, 01:18 PM
            2 responses
            25 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X