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

volume/close of previous day

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

    volume/close of previous day

    I write code of some strategy and I don't know how to check close/volume another day?

    I need following:

    I need to check close/volume of previous day in the same hours
    for example,

    if(previous day)
    if(time == 2 hours pm(for example) )
    if(CloseOfPrevDay < Close[0])
    do smth...

    #2
    Hello Yevhenii,

    Thank you for your note.

    To get the price of the close and the volume at this time yesterday, under OnBarUpdate you should post the following,
    DateTime nowDate =DateTime.Now; //Saves the current Date/Time to variable nowDate

    nowDate= nowDate.AddDays(-1); //Subtracts 1 day from the date of nowDate

    int yesBarsAgo = GetBar(nowDate); //Gives you how many bars ago 1 day ago at this time was.

    double yesClose = Close[yesBarsAgo]; //Assigns the closing price of yesterday on this bar to yesClose variable.

    double yesVolume = Volume[yesBarsAgo]; //Assigns the volume of yesterday on this bar to yesVolume variable.

    Print("Time "+Time[yesBarsAgo]+"YesVolume = "+yesVolume.ToString() +" YesClose "+yesClose);

    You should now be able to use yesClose and yesVolume in your condition.
    Please see AddDays Method:
    Returns a new DateTime that adds the specified number of days to the value of this instance.


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for sharing the information, it is of interest to many people.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by prdecast, Today, 06:07 AM
      0 responses
      2 views
      0 likes
      Last Post prdecast  
      Started by i019945nj, 12-14-2023, 06:41 AM
      3 responses
      60 views
      0 likes
      Last Post i019945nj  
      Started by TraderBCL, Today, 04:38 AM
      2 responses
      17 views
      0 likes
      Last Post TraderBCL  
      Started by martin70, 03-24-2023, 04:58 AM
      14 responses
      106 views
      0 likes
      Last Post martin70  
      Started by Radano, 06-10-2021, 01:40 AM
      19 responses
      610 views
      0 likes
      Last Post Radano
      by Radano
       
      Working...
      X