Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add instrument to chart in STRATEGY Analyzer

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

    #16
    Hello alexstox,

    Thank you for your response.

    You can find an example of creating an instrument input in the SpreadCandlesticks indicator at the following link: http://www.ninjatrader.com/support/f...d=4&linkid=512

    Comment


      #17
      You don't need to use Set. Just show a SMA(1)

      Comment


        #18
        Originally posted by Baruch View Post
        You don't need to use Set. Just show a SMA(1)
        Are you kidding? Can you show me on what post# is your reply?

        Comment


          #19
          [QUOTE][Values[0].Set(Closes[0][0]);
          Values[1].Set(Closes[1][0]);
          Values[2].Set(Closes[2][0]);/QUOTE]
          SMA(1)[1][0];
          SMA(1)[2][0];
          ...

          Comment


            #20
            [QUOTE=Baruch;360044]
            [Values[0].Set(Closes[0][0]);
            Values[1].Set(Closes[1][0]);
            Values[2].Set(Closes[2][0]);/QUOTE]
            SMA(1)[1][0];
            SMA(1)[2][0];
            ...
            I'm sorry, maybe I can't understand something?! What is "SMA" in your post? Because I didn't use SimpleMovingAverage in script.

            Comment


              #21
              The better question is what is SMA(1)[0]?
              The answer: Close[0]
              And SMA(1)[1][0] -> Closes[1][0]

              Comment


                #22
                Originally posted by Baruch View Post
                The better question is what is SMA(1)[0]?
                The answer: Close[0]
                And SMA(1)[1][0] -> Closes[1][0]
                where can I find more info about this?

                Comment


                  #23
                  Originally posted by NinjaTrader_PatrickH View Post
                  Hello alexstox,

                  Thank you for your response.

                  You can find an example of creating an instrument input in the SpreadCandlesticks indicator at the following link: http://www.ninjatrader.com/support/f...d=4&linkid=512
                  1) Where to read about "try ... catch ..." in scripting? There are a lot of things I didn't find in Guide. Where can I read about it?

                  2) "BarsPeriod.Id, BarsPeriod.Value" - these for default value? or what?

                  3) Does this correct mistake in symbol name?
                  Code:
                  if ((symbol2 == "") && (ChartControl != null) && (Instruments != null)) 
                  for(int i=0; i<ChartControl.BarsArray.Length; i++)
                  if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
                  {
                  symbol2 = ChartControl.BarsArray[i].Instrument.FullName;
                  break;
                  }
                  return symbol2;

                  Comment


                    #24
                    Hello alexstox,

                    Thank you for your response.
                    Originally posted by alexstox View Post
                    1) Where to read about "try ... catch ..." in scripting? There are a lot of things I didn't find in Guide. Where can I read about it?
                    You can find information on using try-catch in your code for debugging at the following link: http://www.ninjatrader.com/support/f...ead.php?t=9825
                    Originally posted by alexstox View Post
                    2) "BarsPeriod.Id, BarsPeriod.Value" - these for default value? or what?
                    BarsPeriod.Id will use the period type selected for the main data series you applied to the chart. BarsPeriod.Value will be the value of the main data series, so in the case your chart is a 1 minute chart the Value is 1.
                    Originally posted by alexstox View Post
                    3) Does this correct mistake in symbol name?
                    Code:
                    if ((symbol2 == "") && (ChartControl != null) && (Instruments != null)) 
                    for(int i=0; i<ChartControl.BarsArray.Length; i++)
                    if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
                    {
                    symbol2 = ChartControl.BarsArray[i].Instrument.FullName;
                    break;
                    }
                    return symbol2;
                    I do not understand why this code is needed. What are you running into that you need to check that the instrument name is correct?

                    I look forward to your response.

                    Comment


                      #25
                      Code:
                        [Description("Symbol 2; i.e. SPY or ES 03-10\nDefault = Secondary chart instrument")]
                      [GridCategory("Parameters")]
                      // Force this parameter to be displayed second
                      [Gui.Design.DisplayName ("\t\tSymbol 2")]
                      public string Symbol2
                      {
                       get 
                      {   // symbol2 defaults to secondary chart data series
                      if ((symbol2 == "") && (ChartControl != null) && (Instruments != null)) 
                      for(int i=0; i<ChartControl.BarsArray.Length; i++)
                      if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
                      {
                      symbol2 = ChartControl.BarsArray[i].Instrument.FullName;
                      break;
                      }
                      return symbol2; 
                      			}
                      set { symbol2 = value.ToUpper(); }
                      }
                      Oh, I just copied this from sample that you gave me - SpreadCandlesticks. I just want to know for what this.

                      Comment


                        #26
                        Why still doesn't work?
                        Code:
                        #region Variables
                        private string myIndex1 = "";
                        ......
                        protected override void Initialize()
                        {
                        Add(MyIndex1, PeriodType.Day, 1);
                        Add(new Plot(Color.Orange, "myIndex1"));
                        ........
                        protected override void OnBarUpdate()
                        {
                        if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired)
                        return;
                        			
                        Values[0].Set(Closes[0][0]);
                        .......
                        #region Properties
                        [Description("myIndex1")]
                        [GridCategory("Parameters")]
                        public int MyIndex1
                        {
                        get { return myIndex1; }
                        }
                        .......

                        Comment


                          #27
                          Hello alexstox,

                          Thank you for your response.

                          That is used in the properties section to ensure the same instrument as the main data series is not added.

                          For the second item, I believe you need to change the Closes[0][0] in the following line to Closes[1][0].
                          Code:
                          Values[0].Set(Closes[0][0]); // Change this line to
                          Values[0].Set(Closes[1][0]); // this line.

                          Comment


                            #28
                            Ok. Thanks. I understood =)))
                            So, even when add something in indicator script, only future instrument will be the main ([0]) and any others starts from [1].
                            Last edited by alexstox; 01-20-2014, 11:43 AM.

                            Comment


                              #29
                              There are lots of errors in this case. Why? Script doesn't understand "" as string?
                              Code:
                              namespace NinjaTrader.Indicator
                              {
                              	/// <summary>
                              	/// MyIndex is fundamental indicator
                              	/// </summary>
                              	[Description("Fundamental index indicator")]
                              	public class MyIndex : Indicator
                              	{
                              		#region Variables
                              		private string myIndex1 = "";
                              		private string myIndex2 = "";
                              		private string myIndex3 = "";
                              		#endregion
                              
                              		/// <summary>
                              		/// This method is used to configure the indicator and is called once before any bar data is loaded.
                              		/// </summary>
                              		protected override void Initialize()
                              		{
                              			BarsRequired = 1;
                              			CalculateOnBarClose = true;
                              			HorizontalGridLines = true;
                              			
                              			Add(MyIndex1, PeriodType.Day, 1);
                              			Add(MyIndex2, PeriodType.Day, 1);
                              			Add(MyIndex3, PeriodType.Day, 1);
                              			
                              			Add(new Plot(Color.Orange, "myIndex1"));
                              			Add(new Plot(Color.Yellow, "myIndex2"));
                              			Add(new Plot(Color.Brown, "myIndex3"));
                              			
                              		}
                              
                              		/// <summary>
                              		/// Called on each bar update event (incoming tick)
                              		/// </summary>
                              		protected override void OnBarUpdate()
                              		{
                              			if (CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired || CurrentBars[3] <= BarsRequired)
                              				return;
                              			
                              			Values[0].Set(Closes[1][0]);
                              			Values[1].Set(Closes[2][0]);
                              			Values[2].Set(Closes[3][0]);
                              			
                              		}
                              	
                              			// FormatPriceMarker method of a custom indicator
                              		public override string FormatPriceMarker(double price)
                              		{
                              			// Formats price values to 4 decimal places
                              			return price.ToString("N4");
                              		}
                              
                              
                              		#region Properties
                              		/// <summary>
                              		/// </summary>
                              		[Description("myIndex1")]
                                      [GridCategory("Parameters")]
                              		public int MyIndex1
                                      {
                                          get { return myIndex1; }
                                      }
                              		
                              		[Description("myIndex2")]
                                      [GridCategory("Parameters")]
                              		public int MyIndex2
                                      {
                                          get { return myIndex2; }
                                      }
                              		
                              		[Description("myIndex3")]
                                      [GridCategory("Parameters")]
                              		public int MyIndex3
                                      {
                                          get { return myIndex3; }
                                      }
                              		#endregion
                              	}
                              }

                              Comment


                                #30
                                Hello alexstox,

                                Thank you for your response.
                                Originally posted by alexstox View Post
                                Code:
                                		#region Properties
                                		/// <summary>
                                		/// </summary>
                                		[Description("myIndex1")]
                                        [GridCategory("Parameters")]
                                		public int MyIndex1
                                        {
                                            get { return myIndex1; }
                                        }
                                		
                                		[Description("myIndex2")]
                                        [GridCategory("Parameters")]
                                		public int MyIndex2
                                        {
                                            get { return myIndex2; }
                                        }
                                		
                                		[Description("myIndex3")]
                                        [GridCategory("Parameters")]
                                		public int MyIndex3
                                        {
                                            get { return myIndex3; }
                                        }
                                		#endregion
                                	}
                                }
                                Your strings are set as ints in your properties section. You will need to use strings here as well. The following code should be what your properties section looks like for the string myIndex1 (make sure to repeat this and change the name of the string appropriately for the other strings):
                                Code:
                                		[Description("Index 1.")]
                                        [GridCategory("Parameters")]
                                		[Gui.Design.DisplayName ("Second Index)]
                                        public string MyIndex1
                                        {
                                            get 
                                			{
                                				if ((myIndex1 == "") && (ChartControl != null) && (Instruments != null)) 
                                					for(int i=0; i<ChartControl.BarsArray.Length; i++)
                                						if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
                                						{
                                							 myIndex1 = ChartControl.BarsArray[i].Instrument.FullName;
                                							break;
                                						}
                                				return myIndex1; 
                                			}
                                            set { myIndex1 = value.ToUpper(); }
                                		}

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by andrewtrades, Today, 04:57 PM
                                1 response
                                7 views
                                0 likes
                                Last Post NinjaTrader_Manfred  
                                Started by chbruno, Today, 04:10 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post chbruno
                                by chbruno
                                 
                                Started by josh18955, 03-25-2023, 11:16 AM
                                6 responses
                                436 views
                                0 likes
                                Last Post Delerium  
                                Started by FAQtrader, Today, 03:35 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post FAQtrader  
                                Started by rocketman7, Today, 09:41 AM
                                5 responses
                                19 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Working...
                                X