Announcement

Collapse
No announcement yet.

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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      152 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      89 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      133 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      127 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X