Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add instrument to chart in STRATEGY Analyzer

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

    #31
    Thank you very much, Patrick!!!!!!! How couldn't I see this?! Too lot period near PC =)

    Should this construction be always here?
    Code:
    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(); }
    If I will use DrawLine() instead of Plot() in indicator script, can I draw MyIndex1 to left scale and MyIndex2 to right scale and how to do this?
    Last edited by alexstox; 01-20-2014, 04:33 PM.

    Comment


      #32
      Hello alexstox,

      Thank you for your response.

      The check for the instrument name is not necessary unless it is needed that the instrument not be the same as the main data series.

      For the DrawLine() can you explain which is considered the right and left scale on the chart? Can you provide a screenshot of manually drawn lines for these?

      I look forward to your response.

      Comment


        #33
        Originally posted by NinjaTrader_PatrickH View Post
        Hello alexstox,

        Thank you for your response.

        The check for the instrument name is not necessary unless it is needed that the instrument not be the same as the main data series.

        For the DrawLine() can you explain which is considered the right and left scale on the chart? Can you provide a screenshot of manually drawn lines for these?

        I look forward to your response.
        1) MyIndex1 will be via Plot() on the righ scale and MyIndex2 via DrawLine() on the left scale.

        2)
        Code:
        {
        	/// <summary>
        	/// MyIndex3in1 is fundamental indicator
        	/// </summary>
        	[Description("Fundamental index indicator")]
        	public class MyIndex3in1 : 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;
        //			DrawOnPricePanel = false;
        			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 string MyIndex1
                {
        			 get 
        			{   // symbol2 defaults to secondary chart data series
        				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 /*= value.ToUpper()*/; } //ToUpper used for any symbols to UPPER SYMBOLS
                }
        		
        		[Description("myIndex2")]
                [GridCategory("Parameters")]
        		public string MyIndex2
                {
                   get 
        			{   // symbol2 defaults to secondary chart data series
        				if ((myIndex2 == "") && (ChartControl != null) && (Instruments != null)) 
        					for(int i=0; i<ChartControl.BarsArray.Length; i++)
        						if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
        						{
        							myIndex2 = ChartControl.BarsArray[i].Instrument.FullName;
        							break;
        						}
        				return myIndex2; 
        			}
                    set { myIndex2=value /*= value.ToUpper()*/; }
                }
        		
        		[Description("myIndex3")]
                [GridCategory("Parameters")]
        		public string MyIndex3
                {
                    get 
        	{   // symbol2 defaults to secondary chart data series
        		if ((myIndex3 == "") && (ChartControl != null) && (Instruments != null)) 
        			for(int i=0; i<ChartControl.BarsArray.Length; i++)
        				if (ChartControl.BarsArray[i].Instrument.FullName != [B]Instruments[0].FullName[/B])
        			{
        			myIndex3 = ChartControl.BarsArray[i].Instrument.FullName;
        							break;
        						}
        				return myIndex3; 
        			}
                    set { [B]myIndex3=value[/B] /*= value.ToUpper()*/; } 
                }
        		#endregion
        	}
        }
        After I inserted this indicator to the chart, MyIndex3 is the same as main instrument. Is it because of "Instruments[0].FullName" or "myIndex3=value"? Last I changed because use name of own instruments with upper and lower case. Maybe I did some mistake.

        Comment


          #34
          Hello alexstox,

          Thank you for your response.

          You can use ScaleJustification, however it can only be set to one setting per indicator. So you would need two indicators; one for the plot and one for the DrawLine(): http://www.ninjatrader.com/support/h...tification.htm

          For your second item did you change the string to the desired instrument or leave it blank? If it was blank it will just plot the close of the main series.

          Comment


            #35
            Originally posted by NinjaTrader_PatrickH View Post
            1) You can use ScaleJustification...

            2) For your second item did you change the string to the desired instrument or leave it blank? If it was blank it will just plot the close of the main series.
            1) Well, ScaleJustification is useful only in strategy where I can set it for every indicator.

            2) Can you show me what condition in script command to do this, if I leave it blank?

            3) what is
            Code:
            Instruments[0]
            I didn't find any info in HelpGuide
            Last edited by alexstox; 01-23-2014, 12:34 PM.

            Comment


              #36
              Hello alexstox,

              Thank you for your response.
              Can you show me what condition in script command to do this, if I leave it blank?
              What item are you referring to as blank?

              For your third item, Instruments[0] would be the main instrument the indicator or strategy was applied to.

              Comment


                #37
                Patrick, you wrote
                "For your second item did you change the string to the desired instrument or leave it blank? If it was blank it will just plot the close of the main series."

                Can you please show me what condition command to "plot the close of the main series"?

                Comment


                  #38
                  Alexstox,

                  If you do not define an instrument for the Add() method it will default to create a data series of the main instrument.

                  Not defining it is leaving the test field blank for Myindex3.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #39
                    Hello dear support team. Why after I set ScaleJustification to left and right for 2 indicators in one panel, they still both on right scale? I added those indicators to strategy script.
                    Code:
                    Add(MyIndex(MyIndex1));
                    MyIndex(MyIndex1).Panel=2;
                    MyIndex(MyIndex1).ScaleJustification=ScaleJustification.Left;
                    			
                    Add(MyIndex(MyIndex2));
                    MyIndex(MyIndex2).Panel=2;
                    MyIndex(MyIndex1).ScaleJustification=ScaleJustification.Right;

                    Comment


                      #40
                      Aelxstox,

                      it is because you are changing the same MyIndex scale justification from left to right. Change the second MyIndex to MyIndex(MyIndex2)

                      MyIndex(MyIndex1).ScaleJustification=ScaleJustific ation.Left;

                      MyIndex(MyIndex1).ScaleJustification=ScaleJustific ation.Right;
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #41
                        I saw mistake after reading own question =) Thanks

                        Comment


                          #42
                          Please give me sample where I can manage color and line style of indicator from strategy script.

                          Comment


                            #43
                            Color -
                            Plots[0].Pen.Color = Color.Blue;

                            Plotstyle -
                            Plots[0].PlotStyle = PlotStyle.Line;

                            Plots HelpGuide link -
                            http://www.ninjatrader.com/support/h...html?plots.htm
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #44
                              Originally posted by NinjaTrader_Cal View Post
                              Color -
                              Plots[0].Pen.Color = Color.Blue;

                              Plotstyle -
                              Plots[0].PlotStyle = PlotStyle.Line;

                              Plots HelpGuide link -
                              http://www.ninjatrader.com/support/h...html?plots.htm
                              What mean [0] in Plots[0]? Is it refer to first indicator that added in strategy? And if there are 3 indicators, will be Plots[0], Plots[1], Plots[2]?

                              And what if I need to change Bollinger? (Lower, Upper, MA)?
                              Last edited by alexstox; 01-27-2014, 12:56 PM.

                              Comment


                                #45
                                Correct.

                                However, note that the plots is going to be per indicator that is added to the strategy.

                                So if I added the MACD and SMA to my Strategy.

                                Code:
                                Add(MACD(6,12,9));
                                Add(SMA(14));
                                
                                SMA(14).Plots[0].Pen.Color = Color.Blue;
                                MACD(6,12,19).Plots[0].Pen.Color = Color.Yellow;
                                Each Plots is going to be the indexed plots for that indicator.
                                Since the SMA has only one plot then it would be Plots[0]
                                The MACD has 3 plots so Plots [0,1,2]
                                Cal H.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by rajendrasubedi2023, Today, 09:50 AM
                                0 responses
                                10 views
                                0 likes
                                Last Post rajendrasubedi2023  
                                Started by ender_wiggum, Today, 09:50 AM
                                0 responses
                                4 views
                                0 likes
                                Last Post ender_wiggum  
                                Started by bmartz, Today, 09:30 AM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Started by geddyisodin, Today, 05:20 AM
                                3 responses
                                24 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by lorem, Today, 09:18 AM
                                1 response
                                5 views
                                0 likes
                                Last Post lorem
                                by lorem
                                 
                                Working...
                                X