Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please help me create a Series<T> of a custom data type

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

    Please help me create a Series<T> of a custom data type

    Hi there,
    I want to create a Series<T> of custom data type for use in multiple time intervals. It's tracking some data points on a Daily, a 240-minute, and a 15-minute chart. Please see the bold red text below. Specifically the first line or bold red text. I'm not doing it correctly (duh), and for the life of me I cannot find the correct syntax. Can I declare a Series where I'm trying to so when I run the indicator it doesn't throw an "Indicator 'MarketStructure': Error on calling 'OnBarUpdate' method on bar 20: Object reference not set to an instance of an object." error?
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class MarketStructure : Indicator
    {
    Series<TimeFramePoints> HTF = new Series<TimeFramePoints>; // <-- THIS LINE IS BORKED
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    ...
    }
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute, HighTimeframe); // BarsInProgress index = 1
    }
    else if (State == State.DataLoaded)
    {
    HTF = new Series<TimeFramePoints>(BarsArray[2]);
    }​

    #2
    Hello Nate G,

    Creating an instance of a Series<T> cannot be done in the scope of the class.

    Just declare the variable and create the instance in State.DataLoaded as your are.

    private Series<TimeFramePoints> HTF;

    in State.DataLoaded:
    HTF = new Series<TimeFramePoints>(BarsArray[1]);

    I put BarsArray[1] to synchronize to that data series as there is no BarsArray[2] in your suggested code.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    43 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    25 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    162 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    98 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    158 views
    2 likes
    Last Post CaptainJack  
    Working...
    X