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

Create array with only X values

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

    Create array with only X values

    I am somewhat familiar with the DataSeries class which normally contains the same number of elements as bars in a chart.

    Is there another way to limit the number of elements of a DataSeries? Say I only wanted my DataSeries to contain 100 elements and never more than 100. Can this be done, and if so, how?

    Thanks

    #2
    Hi Pepperdog,

    my shot for a framework.
    The access to the data collection is done with the related bar number. If you operate with CurrentBar, then the last 100 values are stored.
    Code is not tested.

    Regards
    Ralph
    Code:
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New]using[/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][FONT=Courier New][SIZE=2] System.Collections.Generic;[/SIZE][/FONT][/SIZE]
     
    [SIZE=2][SIZE=2][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New]private[/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][FONT=Courier New][SIZE=2][SIZE=2][COLOR=#000000] List<[COLOR=#0000ff]double[/COLOR]> barData = [/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=#000000] List<[COLOR=#0000ff]double[/COLOR]>();[/COLOR][/SIZE][/SIZE][/FONT]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New]private [/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=#000000] listSize = 100;[/COLOR][/SIZE][/SIZE][/FONT]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New]public [/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=#000000] WriteBarData([COLOR=#0000ff]int [COLOR=#000000]barID, [COLOR=#0000ff]double[/COLOR] barValue[/COLOR][/COLOR])[/COLOR][/SIZE][/SIZE][/FONT]
    [SIZE=2][SIZE=2][FONT=Courier New][COLOR=#000000]{[/COLOR][/FONT][/SIZE][/SIZE]
    [FONT=Courier New][COLOR=#000000] barData[barID % listSize] = barValue;[/COLOR][/FONT]
    [SIZE=2][SIZE=2][FONT=Courier New][COLOR=#000000]}[/COLOR][/FONT][/SIZE][/SIZE]
    [SIZE=2][SIZE=2][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New]public [/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=#000000] ReadBarData([COLOR=#0000ff]int [COLOR=#000000]barID[/COLOR][/COLOR])[/COLOR][/SIZE][/SIZE][/FONT]
    [SIZE=2][SIZE=2][FONT=Courier New][COLOR=#000000]{[/COLOR][/FONT][/SIZE][/SIZE]
    [FONT=Courier New][COLOR=#000000] [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return [/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE]barData[barID % listSize];[/COLOR][/FONT]
    [SIZE=2][SIZE=2][FONT=Courier New][COLOR=#000000]}[/COLOR][/FONT][/SIZE]
    [/SIZE][/SIZE][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/SIZE][/SIZE]

    Comment


      #3
      Thanks for posting this code snippet Ralph!

      Here is a link to ArrayLists on MSDN - http://msdn.microsoft.com/en-us/libr...arraylist.aspx
      BertrandNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Started by alifarahani, Today, 09:40 AM
      6 responses
      41 views
      0 likes
      Last Post alifarahani  
      Working...
      X