• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PivotsPlus (derived from standard Pivots indicator)

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

    PivotsPlus (derived from standard Pivots indicator)

    Hi,

    I've copied the default NT Pivots indicator into a PivotsPlus indicator and tried to add a 4th Support and Resistance zone (s4 and r4).

    But unfortunately it gives an "Index was outside the bounds of array" error in the OnBarUpdate method. I've tried everything but can't seem to figure out the location of the error.

    Anybody help?

    I can't paste the complete code because it's too long. But basically I just the same as the Pivots indicator as shipped with NT. I only added some S4 and R4 rows.

    Code:
    		protected override void Initialize()
    		{
    			Add(new Plot(Color.White,	"PP"));
    			Add(new Plot(Color.Red,		"R1"));
    			Add(new Plot(Color.Lime,	"S1"));
    			Add(new Plot(Color.Red,		"R2"));
    			Add(new Plot(Color.Lime,	"S2"));
    			Add(new Plot(Color.Red,		"R3"));
    			Add(new Plot(Color.Lime,	"S3"));
    			Add(new Plot(Color.Red,		"R4"));
    			Add(new Plot(Color.Lime,	"S4"));
    			
    			AutoScale					= false;
    			Overlay						= true;
    			stringFormatFar.Alignment	= StringAlignment.Far;
    		}
    
    		/// <summary>
    		/// Called on each bar update event (incoming tick)
    		/// </summary>
    		protected override void OnBarUpdate()
    		{
    			if (Bars == null)
    				return; 
    			if (!Bars.BarsType.IsIntraday && Bars.Period.Id != PeriodType.Day)
    				return;
    			if (Bars.Period.Id == PeriodType.Day && pivotRangeType == PivotRange.Daily)
    				return;
    			if (Bars.Period.Id == PeriodType.Day && Bars.Period.Value > 1)
    				return;
    
    			// pivots only work for 
    			// - intraday
    			// - 1 day chart with PivotRange Weekly or Monthly
    
    			if (!isDailyDataLoaded)
    			{
    				if (priorDayHLC == HLCCalculationMode.DailyBars && Bars.BarsType.IsIntraday) 
    				{
    					Enabled = false;
    					System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetBarsNow));
    					return;
    				}
    
    				existsHistDailyData = false;
    				isDailyDataLoaded	= true;
    			}
    
    			IBar dailyBar;
    			if (existsHistDailyData) 
    			{
    				sessionDateDaily = GetLastBarSessionDate(Time[0], Bars, PivotRange.Daily);
    				dailyBar = dailyBars.Get(dailyBars.GetBar(sessionDateDaily));
    
    				if (dailyBar.Time.Date > sessionDateDaily.Date)
    				{
    					for (DateTime i = sessionDateDaily; i >= dailyBars.GetTime(0); i = i.AddDays(-1))
    					{
    						dailyBar = dailyBars.Get(dailyBars.GetBar(i));
    						if (dailyBar.Time.Date == i.Date)
    							break;
    					}
    				}
    			} 
    			else 
    				dailyBar = null;
    
    			double	high		= existsHistDailyData ? dailyBar.High : High[0];
    			double	low			= existsHistDailyData ? dailyBar.Low : Low[0];
    			double	close		= existsHistDailyData ? dailyBar.Close : Close[0];
    
    			DateTime lastBarTimeStamp = GetLastBarSessionDate(Time[0], Bars, pivotRangeType);
    			if ((currentDate != Cbi.Globals.MinDate && pivotRangeType == PivotRange.Daily && lastBarTimeStamp != currentDate)
    				|| (currentWeek != Cbi.Globals.MinDate && pivotRangeType == PivotRange.Weekly && lastBarTimeStamp != currentWeek) 
    				|| (currentMonth != Cbi.Globals.MinDate && pivotRangeType == PivotRange.Monthly && lastBarTimeStamp != currentMonth)) 
    			{
    				pp				= (currentHigh + currentLow + currentClose) / 3;
    				s1				= currentClose - 1.1/12*(currentHigh - currentLow);
    				r1				= currentClose + 1.1/12*(currentHigh - currentLow);
    				s2				= currentClose - 1.1/6*(currentHigh - currentLow);
    				r2				= currentClose + 1.1/6*(currentHigh - currentLow);
    				s3				= currentClose - 1.1/4*(currentHigh - currentLow);
    				r3				= currentClose + 1.1/4*(currentHigh - currentLow);
    				s4				= currentClose - 1.1/2*(currentHigh - currentLow);
    				r4				= currentClose + 1.1/2*(currentHigh - currentLow);
    				currentClose	= (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedClose : close;
    				currentHigh		= (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedHigh : high;
    				currentLow		= (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedLow : low;
    			}
    			else
    			{
    				currentClose	= (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedClose : close;
    				currentHigh		= (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedHigh : Math.Max(currentHigh, high);
    				currentLow		= (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedLow : Math.Min(currentLow, low);
    			}
    
    			if (pivotRangeType == PivotRange.Daily)
    				currentDate = lastBarTimeStamp;
    			if (pivotRangeType == PivotRange.Weekly)
    				currentWeek = lastBarTimeStamp;
    			if (pivotRangeType == PivotRange.Monthly)
    				currentMonth = lastBarTimeStamp;
    
    			if ((pivotRangeType == PivotRange.Daily && currentDate != Cbi.Globals.MinDate)
    				|| (pivotRangeType == PivotRange.Weekly && currentWeek != Cbi.Globals.MinDate)
    				|| (pivotRangeType == PivotRange.Monthly && currentMonth != Cbi.Globals.MinDate))
    			{
    				PP.Set(pp);
    				R1.Set(r1);
    				S1.Set(s1);
    				R2.Set(r2);
    				S2.Set(s2);
    				R3.Set(r3);
    				S3.Set(s3);
    				R4.Set(r4);
    				S4.Set(s4);
    			}
    		}
    
    		#region Properties
    		/// <summary>
    		/// </summary>
    		[Description("Type of period for pivot points.")]
    		[GridCategory("Parameters")]
    		public Data.PivotRange PivotRangeType 
    		{
    			get { return pivotRangeType; }
    			set { pivotRangeType = value; }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries PP
    		{
    			get { return Values[0]; }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Description("Approach for calculation the prior day HLC values.")]
    		[GridCategory("Parameters")]
    		public Data.HLCCalculationMode PriorDayHLC
    		{
    			get { return priorDayHLC; }
    			set { priorDayHLC = value; }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries R1
    		{
    			get { return Values[1]; }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries R2
    		{
    			get { return Values[3]; }
    		}
    		
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries R3
    		{
    			get { return Values[5]; }
    		}
    		
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries S1
    		{
    			get { return Values[2]; }
    		}
    		
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries S2
    		{
    			get { return Values[4]; }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries S3
    		{
    			get { return Values[6]; }
    		}
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries R4
    		{
    			get { return Values[7]; }
    		}
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries S4
    		{
    			get { return Values[8]; }
    		}
    
    		/// <summary>
    		/// close value for user defined pivots calculation
    		/// </summary>
    		[Description("User defined prior session close value used for pivots calculation.")]
    		[GridCategory("\rUser defined values")]
    		public double UserDefinedClose
    		{
    			get { return userDefinedClose; }
    			set { userDefinedClose = value; }
    		}
    
    		/// <summary>
    		/// high value for user defined pivots calculation
    		/// </summary>
    		[Description("User defined prior session high value used for pivots calculation.")]
    		[GridCategory("\rUser defined values")]
    		public double UserDefinedHigh
    		{
    			get { return userDefinedHigh; }
    			set { userDefinedHigh = value; }
    		}
    
    		/// <summary>
    		/// low value for user defined pivots calculation
    		/// </summary>
    		[Description("User defined prior session low value used for pivots calculation.")]
    		[GridCategory("\rUser defined values")]
    		public double UserDefinedLow
    		{
    			get { return userDefinedLow; }
    			set { userDefinedLow = value; }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Description("Width of the pivot lines as # of bars.")]
    		[GridCategory("Parameters")]
    		public int Width
    		{
    			get { return width; }
    			set { width = Math.Max(1, value); }
    		}
    		#endregion

    #2
    siroki, I think you missed adding to the brushes collection as well - adding in the below line to your vars section should fix the issue?

    Code:
    private SolidBrush[] brushes = { new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black), new SolidBrush(Color.Black) };
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Awesome, that did the job!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mike Winfrey, Today, 11:27 AM
      0 responses
      2 views
      0 likes
      Last Post Mike Winfrey  
      Started by swcooke, Yesterday, 07:35 PM
      1 response
      18 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by brownsfan019, Today, 10:45 AM
      0 responses
      7 views
      0 likes
      Last Post brownsfan019  
      Started by brownsfan019, Today, 10:41 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by bchip, Today, 09:25 AM
      1 response
      16 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X