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

Pivots Modified

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

    Pivots Modified

    Hello,

    I'm very new to programming and I'm trying to modify the existing NT7 Pivots indicators to include the following changes.

    - New calculations
    - Add Levels S4, S5, R4, R5
    - Plot historical Pivots


    I've added the necessary Variables and new plots...

    Code:
    		protected override void Initialize()
    		{
    			Add(new Plot(Color.Yellow,	"PP"));
    			Add(new Plot(Color.Blue,	"R1"));
    			Add(new Plot(Color.Red,		"S1"));
    			Add(new Plot(Color.Blue,	"R2"));
    			Add(new Plot(Color.Red,		"S2"));
    			Add(new Plot(Color.Blue,	"R3"));
    			Add(new Plot(Color.Red,		"S3"));
    			Add(new Plot(Color.Blue,	"R4"));
    			Add(new Plot(Color.Red,		"S4"));
    			Add(new Plot(Color.Blue,	"R5"));
    			Add(new Plot(Color.Red,		"S5"));
    			
    			AutoScale					= false;
    			Overlay						= true;
    			stringFormatFar.Alignment	= StringAlignment.Far;
    		}

    ...as well as the modified the formulas...
    Code:
    pp				= (currentHigh + currentLow + currentClose) / 3;
    s1				= 2 * pp - currentHigh;
    r1				= 2 * pp - currentLow;
    s2				= pp - (currentHigh - currentLow);
    r2				= pp + (currentHigh - currentLow);
    s3				= s1 - (currentHigh - currentLow);
    r3				= r1 + (currentHigh - currentLow);
    s4				= s2 - (currentHigh - currentLow);
    r4				= r2 + (currentHigh - currentLow);
    s5				= s3 - (currentHigh - currentLow);
    r5				= r3 + (currentHigh - currentLow);

    ... and these changes below...
    Code:
    		/// <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 R4
    		{
    			get { return Values[7]; }
    		}
    		
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries R5
    		{
    			get { return Values[9]; }
    		}
    		
    		/// <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 S4
    		{
    			get { return Values[8]; }
    		}
    
    		/// <summary>
    		/// </summary>
    		[Browsable(false)]
    		[XmlIgnore]
    		public DataSeries S5
    		{
    			get { return Values[10]; }
    		}

    Everything compiles correctly and the indicator shows up then vanishes when prices update.

    Any suggestions?

    Thanks in advanced.

    #2
    Hello TzunTzai,

    Thank you for writing in.

    Have you already done any debugging steps to see why this is occurring?

    We have some helpful debugging tips on our support forum at this link: http://ninjatrader.com/support/forum...58&postcount=1

    What errors appear in the Log tab of the Control Center or in the Tools -> Output Window, if any?
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      Hello TzunTzai,

      Thank you for writing in.

      Have you already done any debugging steps to see why this is occurring?

      We have some helpful debugging tips on our support forum at this link: http://ninjatrader.com/support/forum...58&postcount=1

      What errors appear in the Log tab of the Control Center or in the Tools -> Output Window, if any?

      Thanks for the reply.

      I have not done any debugging at this time. I'll visit the link you provided.

      The Output Windows does not show anything.

      Regards,

      Comment


        #4
        Hello TzunTzai,

        Additionally, do any errors pertaining to your indicator appear in the Log tab of the Control Center?
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ZacharyG View Post
          Hello TzunTzai,

          Additionally, do any errors pertaining to your indicator appear in the Log tab of the Control Center?
          Good call. I didn't check there. Here is the error below.

          Error on plotting indicator 'PivotPoints2'. Please check the 'OnBarUpdate' or the 'Plot' method: Index was outside the bounds of the array.

          Comment


            #6
            Originally posted by NinjaTrader_ZacharyG View Post
            Hello TzunTzai,

            Additionally, do any errors pertaining to your indicator appear in the Log tab of the Control Center?
            I think it has to do with this section of the code...

            Code:
            		protected override void Initialize()
            		{
            			Add(new Plot(Color.Yellow,	"PP"));
            			Add(new Plot(Color.Blue,	"R1"));
            			Add(new Plot(Color.Red,		"S1"));
            			Add(new Plot(Color.Blue,	"R2"));
            			Add(new Plot(Color.Red,		"S2"));
            			Add(new Plot(Color.Blue,	"R3"));
            			Add(new Plot(Color.Red,		"S3"));
            			Add(new Plot(Color.Blue,	"R4"));
            			Add(new Plot(Color.Red,		"S4"));
            			Add(new Plot(Color.Blue,	"R5"));
            			Add(new Plot(Color.Red,		"S5"));
            			AutoScale					= false;
            			Overlay						= true;
            			stringFormatFar.Alignment	= StringAlignment.Far;
            		}
            When I added the plots R4, R5, S4, S5, the problem started.

            Comment


              #7
              Hello TzunTzai,

              Upon further investigation, it looks like the error was occurring within the Plot() override method's for loop that's looping over the seriesCount.

              There wasn't enough brushes within the brushes collection. You will need to add additional brushes within the brushes collection within the Variables region.

              More about the "index was outside the bounds of the array" error can be found at this DotNetPetls link: http://www.dotnetperls.com/indexoutofrangeexception
              Last edited by NinjaTrader_ZacharyG; 03-09-2016, 04:33 PM.
              Zachary G.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ZacharyG View Post
                Hello TzunTzai,

                Upon further investigation, it looks like the error was occurring within the Plot() override method's for loop that's looping over the seriesCount.

                There wasn't enough brushes within the brushes collection. You will need to add additional brushes within the brushes collection within the Variables region.

                More about the "index was outside the bounds of the array" error can be found at this DotNetPetls link: http://www.dotnetperls.com/indexoutofrangeexception

                Perfect, that fixed the problem!

                Second issue... When the Pivots indicator is selected, you can clearly see the historical pivots on the chart.




                How do I go about making these visable? There isnt' an option for it in the settings. I don't mind hard coding this. I do not need an option to disable historical pivots. So, I'm guessing its just a color change? I'm completely stumped here.

                Comment


                  #9
                  Hello,

                  I would suggest taking a look at this forum post on some hints as to how you would be able to plot these values historically: http://ninjatrader.com/support/forum...89&postcount=1
                  Zachary G.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ZacharyG View Post
                    Hello,

                    I would suggest taking a look at this forum post on some hints as to how you would be able to plot these values historically: http://ninjatrader.com/support/forum...89&postcount=1
                    Thank you. I'll have a look.

                    Comment


                      #11
                      ... I've spent all day trying to compare the code and I just can't figure it out. Not sure what I'm missing in order to show historical pivots..

                      Code:
                      		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				= 2 * pp - currentHigh;
                      				r1				= 2 * pp - currentLow;
                      				s2				= pp - (currentHigh - currentLow);
                      				r2				= pp + (currentHigh - currentLow);
                      				s3				= s1 - (currentHigh - currentLow);
                      				r3				= r1 + (currentHigh - currentLow);
                      				s4				= s2 - (currentHigh - currentLow);
                      				r4				= r2 + (currentHigh - currentLow);
                      				s5				= s3 - (currentHigh - currentLow);
                      				r5				= r3 + (currentHigh - currentLow);
                      				rp1m			= (pp + r1) / 2;
                      				sp1m			= (pp + s1) / 2;
                      				r12m			= (r1 + r2) / 2;
                      				s12m			= (s1 + s2) / 2;
                      				r23m			= (r2 + r3) / 2;
                      				s23m			= (s2 + s3) / 2;
                      				r34m			= (r3 + r4) / 2;
                      				s34m			= (s3 + s4) / 2;
                      				r45m			= (r4 + r5) / 2;
                      				s45m			= (s4 + s5) / 2;
                      				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);
                      				R5.Set(r5);
                      				S5.Set(s5);
                      				RP1M.Set(rp1m);
                      				SP1M.Set(sp1m);
                      				R12M.Set(r12m);
                      				S12M.Set(s12m);
                      				R23M.Set(r23m);
                      				S23M.Set(s23m);
                      				R34M.Set(r34m);
                      				S34M.Set(s34m);
                      				R45M.Set(r45m);
                      				S45M.Set(s45m);
                      			}
                      		}
                      Last edited by TzunTzai; 03-11-2016, 07:53 AM.

                      Comment


                        #12
                        Hello TzunTzai,

                        Try commenting out the Plot() override method from your script. This will remove any of the logic that's stopping the indicator from plotting historically.

                        This will also remove the labels for the lines, however. You'll need to ensure that you use DrawText() to draw the labels as well: https://ninjatrader.com/support/help.../?drawtext.htm
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for the input. It helped. Still have a ways to go. My ability to code just isn't there yet. I may have to pass this over to a programmer to knock it out.

                          Comment


                            #14
                            Hello TzunTzai,

                            If you wish to have a programmer to assist with this, please let me know and I will forward you on to our business development department who can connect you with a NinjaScript consultant.
                            Zachary G.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by GussJ, 03-04-2020, 03:11 PM
                            16 responses
                            3,281 views
                            0 likes
                            Last Post Leafcutter  
                            Started by WHICKED, Today, 12:45 PM
                            2 responses
                            19 views
                            0 likes
                            Last Post WHICKED
                            by WHICKED
                             
                            Started by Tim-c, Today, 02:10 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by Taddypole, Today, 02:47 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post Taddypole  
                            Started by chbruno, 04-24-2024, 04:10 PM
                            4 responses
                            53 views
                            0 likes
                            Last Post chbruno
                            by chbruno
                             
                            Working...
                            X