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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      57 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      78 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      41 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      101 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      61 views
      0 likes
      Last Post PaulMohn  
      Working...
      X