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

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 Austiner87, Today, 03:42 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by cshox, Today, 11:11 AM
        2 responses
        15 views
        0 likes
        Last Post cshox
        by cshox
         
        Started by algospoke, Today, 06:53 PM
        0 responses
        9 views
        0 likes
        Last Post algospoke  
        Started by mlprice12, 12-21-2021, 04:55 PM
        3 responses
        297 views
        0 likes
        Last Post paypachaysa  
        Started by lorem, 04-25-2024, 09:18 AM
        20 responses
        86 views
        0 likes
        Last Post lorem
        by lorem
         
        Working...
        X