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 geddyisodin, Today, 05:20 AM
            0 responses
            3 views
            0 likes
            Last Post geddyisodin  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            6 responses
            33 views
            0 likes
            Last Post JonesJoker  
            Started by GussJ, 03-04-2020, 03:11 PM
            12 responses
            3,239 views
            0 likes
            Last Post Leafcutter  
            Started by AveryFlynn, Today, 04:57 AM
            0 responses
            6 views
            0 likes
            Last Post AveryFlynn  
            Started by RubenCazorla, 08-30-2022, 06:36 AM
            3 responses
            79 views
            0 likes
            Last Post PaulMohn  
            Working...
            X