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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      67 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      150 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      99 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      286 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X