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 last 50 values of an indicator at 10.00AM

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

    Get the last 50 values of an indicator at 10.00AM

    How can I get the last 50 values of an indicator at 10.00AM each day?
    So for example the SMA(20) values on
    12/7/2015 @ 10AM
    12/4/2015 @ 10AM
    12/3/2015 @ 10AM
    12/2/2015 @ 10AM
    12/1/2015 @ 10AM
    11/30/2015 @ 10AM
    ...
    10/30/2015 @ 10AM

    Notice that I'm jumping across weeks, months and possibly years.



    I tried using this technique below but then when I go beyond weeks and months I need to start controlling every variable. I'm assuming there is a more direct way.

    Code:
    if (Time[0].DayOfWeek == DayOfWeek.Monday)
    timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 3, 9, 30, 0);
    else
    timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 1, 9, 30, 0);
    
    barsAgo = GetBar(timeOfInterest);
    etc..
    Last edited by Diego Aburto; 12-07-2015, 02:08 PM.

    #2
    Hello Diego Aburto,

    Thanks for your post.

    Can you provide further detail of what you are wanting to get?

    What is the timeframe of the bar data you are using?

    For example if you are looking for the SMA(20) on 10 minute bars you want to know what the prior 50 10 minute values of the SMA(20) starting at 10:00 am and going backwards each day? Or do you mean only 1 sample at 10:00 AM for the last 50 days?

    Please feel free to post a chart example.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Just ONE value.
      1-minute bars.

      I'm going to use the VOL() indicator in the example below on the SPY (see attachment for values).

      VOL() value on 12/7/2015 @ 10AM = 188K
      VOL() value on 12/4/2015 @ 10AM = 599K
      VOL() value on 12/3/2015 @ 10AM = ...
      VOL() value on 12/2/2015 @ 10AM = ...
      VOL() value on 12/1/2015 @ 10AM = ...
      VOL() value on 11/30/2015 @ 10AM = ...
      ...
      VOL() value on 10/30/2015 @ 10AM = ...
      Attached Files
      Last edited by Diego Aburto; 12-07-2015, 03:42 PM.

      Comment


        #4
        Hello Diego Aburto,

        Thanks for your reply and clarification.

        One way to accomplish your goal is using a List to collect the data then checking the last 50 elements of the list.

        To use List, you would need to add using System.Collections.Generic; in the region "Using declaration" at the very top of the file.

        In the variables area add: private List<double> lista = new List<double>();

        lista is the name of the list that the example will store the volume at 10:00 each day. (For 50 days of volume you would need > 75 calendar days of data loaded)

        For example:

        Code:
        			
        
        if (ToTime(Time[0]) == ToTime(10,00,00))   // if Bar = 10:00 am
        {			
        	lista.Add (Volume[0]);    // add the 10 am bar volume to the list
        }
        			
        if ( [I]some condition of yours[/I] && lista.Count > 50)
        {
        	for (int i = 1; i < 51; i++)  // process 50 elements
        	{
        	   Print ("count "+i+ "  Vol: "+lista[lista.Count-i]); // subtract i from the list count
        	}					
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Awesome, thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by PhillT, 04-19-2024, 02:16 PM
          4 responses
          30 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Started by ageeholdings, 05-01-2024, 05:22 AM
          5 responses
          35 views
          0 likes
          Last Post ageeholdings  
          Started by reynoldsn, Today, 02:34 PM
          0 responses
          6 views
          0 likes
          Last Post reynoldsn  
          Started by nightstalker, Today, 02:05 PM
          0 responses
          12 views
          0 likes
          Last Post nightstalker  
          Started by llanqui, Yesterday, 09:59 AM
          8 responses
          29 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Working...
          X