Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
      Brandon H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      14 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,983 views
      3 likes
      Last Post jhudas88  
      Working...
      X