Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Series Initialization

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

    Custom Series Initialization

    Hi!

    I have declared these two series:

    Code:
            private Series<bool> WeakLow;
            private Series<bool> WeakHigh;​
    then I instantiate them as follows:

    Code:
        protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description    = @"";
    
                    [ ... ]
                }
                else if (State == State.Configure)
                {
                }
                else if (State == State.DataLoaded)
                {                
                    WeakLow  = new Series<bool>(this);
                    WeakHigh = new Series<bool>(this);
                }
            }​
    I want to initialize them to false at start up. I will try to do that with a for loop over ChartBars.

    Are there any other more efficient methods?

    #2
    They're not over ChartBars, they're over BarsArray[0] (e.g. Bars). The difference is ChartBars could cover additional data series including whatever the user has put on the chart.

    You shouldn't be trying to initialize their elements until CurrentBars[0] (e.g. CurrentBar if BarsInProgress is 0) is at least that element.

    One approach would be to make the first line in OnBarUpdate something like this:

    if (BarsInProgress == 0 && CurrentBar >= 0 && IsFirstTickOfBar) { WeakLow[0] = false; WeakHigh[0] = false; }

    This would have the effect of having each element of those two series start off each bar being set to false, rather than starting off each bar being unset.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello GianPiero,

      Thanks for your post.

      QuantKey_Bruce has provided some great information regarding this topic.

      The custom Series variables would be over the BarsArray[0] (primary data series) you are running the script on and you could make sure that CurrentBar or CurrentBars[0] is greater than or equal to 0 and check IsFirstTickOfBar is true and set your custom Series variables to false.

      See the help guide documentation below for more information.

      Series<T>: https://ninjatrader.com/support/help...t8/seriest.htm
      CurrentBar: https://ninjatrader.com/support/help...currentbar.htm
      IsFirstTickOfBar: https://ninjatrader.com/support/help...ttickofbar.htm
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      574 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X