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 algospoke, Yesterday, 06:40 PM
      2 responses
      23 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      45 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      21 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      181 views
      0 likes
      Last Post jeronymite  
      Working...
      X