Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Bollinger ( IDataSeries, double stdev ,int period )

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

    Problem with Bollinger ( IDataSeries, double stdev ,int period )

    Hi ,

    I have tried using Indicators for DataSeries, but am getting incorrect values.

    As an example please see the attached ninjascript code: I create a simple ratio dataseries ( last close / 10 ) and use the print command to check the values. The first SMA ( Bollinger (ratio,2,10).Middle) seems to divide the last close price by 100 and the subsequent Bollinger Middle, Lower & Upper values seem to take some garbage values. Could you please help me out with this.

    Thank you,

    Neo
    Attached Files
    Last edited by neo_trader; 09-11-2009, 04:23 PM.

    #2
    Hello,

    Yes, I can. Do you mind posting the critical parts of your code on the forum? Thanks.

    Just in case you haven't seen these links already:

    DenNinjaTrader Customer Service

    Comment


      #3
      Hi Ben,

      Yes, here is the code ( I had attached a zip file earlier ) :

      protected override void Initialize()
      {
      ratio=new DataSeries(this);
      CalculateOnBarClose = true;
      TraceOrders=false;
      }


      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      Print(Close[0]);
      Print( Close[0] + " " + Time[0]);
      Print(Bollinger(ratio,2,10).Lower[0]+ " " + Bollinger(ratio,2,10).Middle[0]+ " "+Bollinger(ratio,2,10).Upper[0]);
      Print( " " );
      // Condition set 1
      if (CrossBelow(Close, Bollinger(1.5, 10).Lower, 3))
      {
      EnterShort(DefaultQuantity, "");
      }

      // Condition set 2
      if (CrossAbove(Close, Bollinger(1.5, 10).Upper, 3))
      {
      EnterLong(DefaultQuantity, "");
      }

      // Condition set 3
      if (CrossBelow(Low, SMA(10), 20))
      {
      ExitLong("", "");
      }

      // Condition set 4
      if (CrossAbove(High, SMA(10), 20))
      {
      ExitShort("", "");
      }
      }

      #region Properties
      [Description("Lower Bollinger ")]
      [Category("Parameters")]
      public double Lowerbl
      {
      get { return lowerbl; }
      set { lowerbl = Math.Max(1, value); }
      }

      [Description("Upper Bollinger ")]
      [Category("Parameters")]
      public double Upperbl
      {
      get { return upperbl; }
      set { upperbl = Math.Max(1, value); }
      }

      [Description("10 day EMA")]
      [Category("Parameters")]
      public double Movingaverage
      {
      get { return movingaverage; }
      set { movingaverage = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Thanks,

      Neo

      Comment


        #4
        Hey Ben,

        I used the links that you provided me and seem to have made some progress. But I have a small query from this link :http://www.ninjatrader-support.com/H...ataSeries.html ,

        if I use return Bollinger (ratio, 1.5,10). Middle [0] in a method, where ratio is a dataseries computed from Closes [0][0] / Closes[1][0], is their a way I can reference the ratio to start from the element in index 1 ( ratio [1] ), so that the Bollinger method would than compute the SMA for ratio [1] to ratio [10]. Please see the code below :

        parts of my code are :

        protected override void Initialize()
        {
        Add(Instrument2, BarsPeriod.Id, BarsPeriod.Value); // Adding secondary instrument

        CalculateOnBarClose = true;

        ratio = new DataSeries(this);
        value = new DataSeries(this);

        TraceOrders=true;

        }

        private double BollMiddle(IDataSeries priceData)
        {
        return Bollinger(priceData,1.5,10).Middle[1];
        }

        private double BollUpper(IDataSeries priceData)
        {
        return Bollinger(priceData,1.5,10).Upper[1];
        }


        private double BollLower(IDataSeries priceData)
        {
        return Bollinger(priceData,1.5,10).Lower[1];
        }

        protected override void OnBarUpdate()
        {

        if ( BarsInProgress==0 )
        {
        inst1close=Closes[0][0];
        Print(Closes[0][0]+" " + Time[0]);

        if (CurrentBar >= BarsRequired+ratio_period)
        {

        for(int i=0;i<=9;i++)
        {
        Print(ratio[i]);
        }

        Print(BollUpper ( ratio )+" "+ BollMiddle ( ratio )+" "+ BollLower(ratio));

        From the last statement that I print, the Bollupper, middle, lower values are incorrect because in the methods BollMiddle etc. Bollinger ( pricedata ,... ) computes the ratios from ratio [0] which happens to be zero during Barsinprogress==0 . Bottomline is how do I reference the pricedata array from index 1 ?

        Thanks,

        Neo

        Comment


          #5
          Hello,

          I'm not sure what you are after here. I am afraid you'll need to debug it.
          DenNinjaTrader Customer Service

          Comment


            #6
            Hi

            Hi Ben,

            I guess I confused you by giving too much.

            One simple question -- how do I reference a dataseries array from INDEX [1] when I use the overloaded indicator method.
            eg : Bollinger ( IDataSeries, double stdev, int period ) .

            so how do I use this in a way such that Bollinger (myDataSeries,1.5,10) is applied from DataSeries[1] ?

            Thank you,

            Neo

            Comment


              #7
              Bollinger(Closes[1],......)
              Bollinger(Highs[1],....)
              etc.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Hi Josh,

                I used it as follows and commented those lines in upper case. However, I get the following compilation errors:

                The best overloaded method match for 'NinjaTrader.Strategy.Strategy.Bollinger(NinjaTrad er.Data.IDataSeries) has invalid arguments
                Argument '1': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'

                Here is part of the code :

                protected override void Initialize()
                {
                Add(Instrument2, BarsPeriod.Id, BarsPeriod.Value); // Adding secondary instrument

                CalculateOnBarClose = true;

                ratio = new DataSeries(this);
                value = new DataSeries(this);

                TraceOrders=true;

                }

                private double BollMiddle(IDataSeries priceData)
                {
                return Bollinger(priceData[1],1.5,10).Middle[1]; // USED INDEX [1] HERE
                }

                private double BollUpper(IDataSeries priceData)
                {
                return Bollinger(priceData [1],1.5,10).Upper[1]; // USED INDEX[1] HERE
                }


                private double BollLower(IDataSeries priceData)
                {
                return Bollinger(priceData[1],1.5,10).Lower[1]; // USED INDEX[1] HERE
                }

                protected override void OnBarUpdate()
                {

                if ( BarsInProgress==0 )
                {
                inst1close=Closes[0][0];
                Print(Closes[0][0]+" " + Time[0]);

                if (CurrentBar >= BarsRequired+ratio_period)
                {

                for(int i=0;i<=9;i++)
                {
                Print(ratio[i]);
                }

                Print(BollUpper ( ratio )+" "+ BollMiddle ( ratio )+" "+ BollLower(ratio));

                Thanks,

                Neo
                Last edited by neo_trader; 09-16-2009, 04:11 PM.

                Comment


                  #9
                  neo_trader, the way you have it setup now you pass a double into the Bollinger overload, while it expects a dataseries - http://www.ninjatrader-support.com/H...BarSeries.html

                  Comment


                    #10
                    I understand that the overloaded method requires a dataseries input and not a double value. But since mydataseries ( ratio ) is being computed using Closes[0][0]/Closes[1][0] in the BarsInProgress loop, I can't use the BarsArray. This is because I can't do a
                    Add(mydataseries).I hope you understood what I am trying to say here. Please let me know if this not the correct line of thinking.

                    Thanks,

                    Neo

                    Comment


                      #11
                      Then please try this, just don't access a double object via the index from the pricedata dataseries you created -

                      Code:
                       
                      private double BollMiddle(IDataSeries priceData) 
                      {
                      return Bollinger(priceData, 1.5, 10).Middle[1]; // USED INDEX [1] HERE 
                      }

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      648 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      369 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      108 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      572 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      574 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X