Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error with DataSeries

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

    Error with DataSeries

    Hi,

    I am trying to use Bollinger Bands for my custom made MA. However, I get an error saying the 'Values[0]' does not exist in the current context. I have defined them in properties as per the Indicator code of Bollinger Bands :

    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Lower
    {
    get { return Values[0]; }
    }

    /// <summary>
    /// Get the upper value.
    /// </summary>
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Upper
    {
    get { return Values[0]; }
    }


    Can you please tell me why I am getting this error for Values[0] ?

    Thanks,

    Neo

    #2
    Hello Neo_trader,

    One issue with the snippet you posted is the Values index[ ] needs to be incremented by one for each series defined.

    Code:
    /// Get the upper value.
    /// </summary>
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Upper
    {
    get { return Values[[COLOR=red][B]1[/B][/COLOR]]; }
    }

    However you shouldn't need to code in properties for Bollinger Band in a strategy. The indicator and all associated properties are called automatically.

    Let us know what you're trying to do with Bollinger and we can assist further. If you wanted a moving average of bollinger bands for example, you could write:
    SMA(Bollinger(2, 14).Upper, 14)[0]
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      What I am trying to do is use Bollinger on a Spread Value (between two instruments). So I want to create an entry based on the Spread value crossing the Bollinger Upper, Lower and Middle values. How can I use these three values in my strategy using the Bollinger (Spread,Period) function. Please assume the Spread here is a DataSeries.

      Neo

      Comment


        #4
        Neotrader,

        Bollinger can take a dataseries as input. Below snippet will plot based on the three elements of Bollinger, accepting spread as data series input:

        Plot0.Set(Bollinger(spread, 2, 14)[0]);
        Plot1.Set(Bollinger(spread, 2, 14).Upper[0]);
        Plot2.Set(Bollinger(spread, 2, 14).Lower[0]);


        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        59 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        283 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X