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

PriorDayOHLC().PriorClose[] function

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

    PriorDayOHLC().PriorClose[] function

    Hi,

    I'm using a minute chart and trying to extract the yesterday's close and the day before yesterday's close but I seem to be getting the same data for both days.

    From the attached chart, you can see the close for the previous 3 days are different but the output is showing the same data.

    here is my code:-
    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
    double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] C2A = PriorDayOHLC().PriorClose[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]];[/COLOR]
    Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Close[2] is "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + PriorDayOHLC().PriorClose[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].ToString());
    [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] C1A = PriorDayOHLC().PriorClose[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];
    Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Close[1] is "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + PriorDayOHLC().PriorClose[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].ToString());
    [/SIZE][/FONT][/SIZE][/FONT]
    Please help. Thx

    Kay Wai
    Attached Files

    #2
    Kay Wai, the PriorDayOHLC() indicator returns the previous day's close for every single bar on the current day, so you'll have to reference quite a few more bars back to get to yesterday's closing. Please see this reference sample for how to grab an indicator value from a specific date/time.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin,

      I'm using the "Bars.GetDayBar(2).Close" function now to extract the data but the issue with this 1) I need to make sure there are enough bars and 2) if I were to use a higher timeframe, I would either need to adjust the code or make sure I have enough bars for the data to be extracted.

      Isn't there a better way?

      Regards

      Kay Wai

      Comment


        #4
        Kay Wai, unfortunately the methods you mention would be the best way to do this. If you use a higher timeframe, it should still work correctly because the day bars are "virtual bar[s] built off of the underlying data series".
        AustinNinjaTrader Customer Service

        Comment


          #5
          Hi Austin,

          Thank you for your reply. The reason why I asked the question is because when I wrote the code "If (CurrentBar < 5) return", I was given an error BUT when I placed "If (CurrentBar <3600) return, there weren't any problems. Do you think the issue could be with PriorDay OHLC or Bars.GetDayBar or both?

          Regards

          Kay Wai

          Comment


            #6
            Kay Wai, you'll have to make sure there are enough bars for either case. If you try to access a value that doesn't exist (like checking yesterday's close on the very first bar of the chart), you will get an error. The easiest way to get around this is to include a big current bar check (if currentbar < 3600, like in your example) and then include more chart data to make up for the "lost" day of data.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Originally posted by kaywai View Post
              Hi Austin,

              Thank you for your reply. The reason why I asked the question is because when I wrote the code "If (CurrentBar < 5) return", I was given an error BUT when I placed "If (CurrentBar <3600) return, there weren't any problems. Do you think the issue could be with PriorDay OHLC or Bars.GetDayBar or both?

              Regards

              Kay Wai
              If you are using GetDayBar(), you MUST do a null check.

              Comment


                #8
                Hi Koganam, not sure what you mean by a null check. Do you mean that to make sure there are bar data available?

                Hi Austin, what I am trying to get at is when I use CurrentBar < 3600, that is for the 1 minute because I'm trying to get to 2 days ago but if I'm using 4 hour bars and the setting is still 3600, that would mean I would have to 864000 1 minute pieces of data available for uploading...correct? And all this just to extract a piece of information from 2 days ago...correct?

                Comment


                  #9
                  Originally posted by kaywai View Post
                  Hi Koganam, not sure what you mean by a null check. Do you mean that to make sure there are bar data available?

                  Hi Austin, what I am trying to get at is when I use CurrentBar < 3600, that is for the 1 minute because I'm trying to get to 2 days ago but if I'm using 4 hour bars and the setting is still 3600, that would mean I would have to 864000 1 minute pieces of data available for uploading...correct? And all this just to extract a piece of information from 2 days ago...correct?
                  Code:
                  if (Bars.GetDayBar(int lookBackDays) != null)
                  {
                  //Do something
                  }
                  That way you do not throw an exception, as the block does not process until there are enough bars for there to be a valid day bar for the day in which you are interested.

                  Comment


                    #10
                    Thanks for the tip Koganam. Appreciate it!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by naanku, Today, 07:25 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post naanku
                    by naanku
                     
                    Started by milfocs, Today, 07:23 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post milfocs
                    by milfocs
                     
                    Started by PaulMohn, Today, 06:59 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post PaulMohn  
                    Started by bortz, 11-06-2023, 08:04 AM
                    48 responses
                    1,750 views
                    0 likes
                    Last Post carnitron  
                    Started by Jonker, 04-27-2024, 01:19 PM
                    3 responses
                    23 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X