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

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 CortexZenUSA, Today, 12:53 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by usazencortex, Today, 12:43 AM
            0 responses
            5 views
            0 likes
            Last Post usazencortex  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            168 responses
            2,265 views
            0 likes
            Last Post sidlercom80  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            11 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X