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

BackColor Only to Indicator Panel?

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

    BackColor Only to Indicator Panel?

    Hello:

    I'm trying to simply BackColor the indicator panel, i.e. not the primary Data Series panel as well. So far doesn't seem possible using this basic function though.

    Any ideas out there to the contrary ?

    Thanks.
    Last edited by tradenj; 06-14-2013, 01:35 PM.

    #2
    Hello tradenj,

    Yes, this can be done using the BackColor inside of the Indicator. Here is a link to our Help Guide that you may use as a reference.

    JCNinjaTrader Customer Service

    Comment


      #3
      Prior Attempt at this Didn't Work

      Hello:
      Thank you for your quick response.

      Here's a short piece of code I created earlier today using BackColor inside an indicator but it doesn't seem to work. I ran it with "NQ 09-13" as primary Data Series.

      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Strategy;
      #endregion
      
      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
          /// <summary>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class Support1 : Strategy
          {
              #region Variables
              // Wizard generated variables
              private int myInput0 = 1; // Default setting for MyInput0
              // User defined variables (add any user defined variables below)
      		#endregion
      
              /// <summary>
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              /// </summary>
              protected override void Initialize()
              {
      			Add(MACD(12, 26, 9));
      			CalculateOnBarClose = true;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      			if (BarsInProgress==0)
      				BackColor = CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1) ? Color.Salmon : Color.Empty;
      		}
      
              #region Properties
              [Description("")]
              [GridCategory("Parameters")]
              public int MyInput0
              {
                  get { return myInput0; }
                  set { myInput0 = Math.Max(1, value); }
              }
              #endregion
          }
      }

      Comment


        #4
        Hello tradenj,

        Thanks for the sample code.

        You code is working as seen on the screenshot below.

        The reason why it is plotting on the Data Series is because you are setting the backcolor inside of a Strategy.

        If you would it to be placed inside of the Indicator Panel then you would have to create an indicator that does this same thing so that you can define what Panel it is plotting on.

        A Strategy is always going to use the Primary Data Series first.
        Attached Files
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by tradenj View Post
          Hello:
          Thank you for your quick response.

          Here's a short piece of code I created earlier today using BackColor inside an indicator but it doesn't seem to work. I ran it with "NQ 09-13" as primary Data Series.

          Code:
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Strategy;
          #endregion
           
          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
              /// <summary>
              /// Enter the description of your strategy here
              /// </summary>
              [Description("Enter the description of your strategy here")]
              public class Support1 : Strategy
              {
                  #region Variables
                  // Wizard generated variables
                  private int myInput0 = 1; // Default setting for MyInput0
                  // User defined variables (add any user defined variables below)
                  #endregion
           
                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
                      Add(MACD(12, 26, 9));
                      CalculateOnBarClose = true;
                  }
           
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                      if (BarsInProgress==0)
                          BackColor = CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1) ? Color.Salmon : Color.Empty;
                  }
           
                  #region Properties
                  [Description("")]
                  [GridCategory("Parameters")]
                  public int MyInput0
                  {
                      get { return myInput0; }
                      set { myInput0 = Math.Max(1, value); }
                  }
                  #endregion
              }
          }
          The indicator is an object. Create a named instance of the indicator, and modify the BackColor property of the named instance.

          Comment


            #6
            Hello again:

            Thanks to you both for your helpful posts. I've now transformed all of my previous code into just indicators. -Another great process of simplification discovered here in Ninja.

            I'm having one indicator coding problem now though as follows. The sample code listed below produces the expected output when executed on for instance "NQ 09-13", i.e. an NQ chart with peach backcolor at various bars. If the first line of code within OnBarUpdate() however is changed to
            Code:
            SMA0=SMA(14)[1];
            this runtime error occurs:
            Error on calling 'OnBarUpdate' method for indicator 'Support' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
            Any ideas on how to fix this would be appreciated.
            Code:
            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Diagnostics;
            using System.Drawing;
            using System.Drawing.Drawing2D;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Data;
            using NinjaTrader.Gui.Chart;
            #endregion
            
            // This namespace holds all indicators and is required. Do not change it.
            namespace NinjaTrader.Indicator
            {
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                [Description("Enter the description of your new custom indicator here")]
                public class Support : Indicator
                {
                    #region Variables
                    // Wizard generated variables
                    // User defined variables (add any user defined variables below)
            		public double SMA0 = 0;	
                    
            		#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()
                    {
                        Overlay				= true;
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
            			SMA0=SMA(14)[0];    /* Change to [1] => Run Time Error */
            			if (Lows[0][1]<SMA0)
            				BackColorSeries[0] = Color.PeachPuff;
            			
            			// Use this method for calculating your indicator values. Assign a value to each
                        // plot below by replacing 'Close[0]' with your own formula.
                    }
            
                    #region Properties
            
                    #endregion
                }
            }
            
            #region NinjaScript generated code. Neither change nor remove.
            // This namespace holds all indicators and is required. Do not change it.
            namespace NinjaTrader.Indicator
            {
                public partial class Indicator : IndicatorBase
                {
                    private Support[] cacheSupport = null;
            
                    private static Support checkSupport = new Support();
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public Support Support()
                    {
                        return Support(Input);
                    }
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public Support Support(Data.IDataSeries input)
                    {
                        if (cacheSupport != null)
                            for (int idx = 0; idx < cacheSupport.Length; idx++)
                                if (cacheSupport[idx].EqualsInput(input))
                                    return cacheSupport[idx];
            
                        lock (checkSupport)
                        {
                            if (cacheSupport != null)
                                for (int idx = 0; idx < cacheSupport.Length; idx++)
                                    if (cacheSupport[idx].EqualsInput(input))
                                        return cacheSupport[idx];
            
                            Support indicator = new Support();
                            indicator.BarsRequired = BarsRequired;
                            indicator.CalculateOnBarClose = CalculateOnBarClose;
            #if NT7
                            indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                            indicator.MaximumBarsLookBack = MaximumBarsLookBack;
            #endif
                            indicator.Input = input;
                            Indicators.Add(indicator);
                            indicator.SetUp();
            
                            Support[] tmp = new Support[cacheSupport == null ? 1 : cacheSupport.Length + 1];
                            if (cacheSupport != null)
                                cacheSupport.CopyTo(tmp, 0);
                            tmp[tmp.Length - 1] = indicator;
                            cacheSupport = tmp;
                            return indicator;
                        }
                    }
                }
            }
            
            // This namespace holds all market analyzer column definitions and is required. Do not change it.
            namespace NinjaTrader.MarketAnalyzer
            {
                public partial class Column : ColumnBase
                {
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    [Gui.Design.WizardCondition("Indicator")]
                    public Indicator.Support Support()
                    {
                        return _indicator.Support(Input);
                    }
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public Indicator.Support Support(Data.IDataSeries input)
                    {
                        return _indicator.Support(input);
                    }
                }
            }
            
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
                public partial class Strategy : StrategyBase
                {
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    [Gui.Design.WizardCondition("Indicator")]
                    public Indicator.Support Support()
                    {
                        return _indicator.Support(Input);
                    }
            
                    /// <summary>
                    /// Enter the description of your new custom indicator here
                    /// </summary>
                    /// <returns></returns>
                    public Indicator.Support Support(Data.IDataSeries input)
                    {
                        if (InInitialize && input == null)
                            throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
            
                        return _indicator.Support(input);
                    }
                }
            }
            #endregion
            Last edited by tradenj; 06-16-2013, 12:07 PM.

            Comment


              #7
              OnBarUpdate() is executed for all bars of your chart, starting with bar 0.

              When it is executed for the first bar, CurrentBar == 0, then SMA[1] is not defined, as this would be the moving average for CurrentBar == -1, which unfortunately does not exist.

              What you need to do, is to prevent that OnBarUpdate() is executed for CurrentBar == 0, but simply start the execution with CurrentBar == 1.

              This can be achieved, if you add the following code in the beginning of OnBarUpdate()


              Code:
              if(CurrentBar == 0)
                return;

              Comment


                #8
                Hi:

                -Yes, indicator now executes with additional code. Thanks for this solution.

                My question here though is wouldn't the real time output always be one bar behind and of less value/ use for this reason? Also, the original code (taken from a strategy I converted to an indicator) always executed with no problem. Its underlying chart had two data series and read something like this:

                Code:
                if (BarsInProgress == 1) 
                { 
                       SMA1=SMA(14)[1];
                       if (Lows[1][1]<SMA1) 
                            if  (Highs[1][0]>SMA1)
                                  /* ... do xyz  */
                }
                Last edited by tradenj; 06-16-2013, 03:30 PM.

                Comment


                  #9
                  Hello tradenj,

                  Thank you for your response.

                  You actually want to check to make sure you have enough bars on the chart before accessing the values. If you are accessing [1] you need to ensure there are more than 1 bars on the chart.

                  For information on this matter please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

                  Please let me know if I may be of further assistance.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by judysamnt7, 03-13-2023, 09:11 AM
                  4 responses
                  59 views
                  0 likes
                  Last Post DynamicTest  
                  Started by ScottWalsh, Today, 06:52 PM
                  4 responses
                  36 views
                  0 likes
                  Last Post ScottWalsh  
                  Started by olisav57, Today, 07:39 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post olisav57  
                  Started by trilliantrader, Today, 03:01 PM
                  2 responses
                  22 views
                  0 likes
                  Last Post helpwanted  
                  Started by cre8able, Today, 07:24 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X