• 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

Expose Properties of Indicator

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

    Expose Properties of Indicator

    I have a custom indicator that paints the bars that I want to use in a strategy. Looks like the main logic is in a public class. But there is also a section of code that seems to paint the bars:
    Code:
    internal double GetValue(double close, out string format, out Color color, out Color bkColor, out string alertText, DateTime now)
            {
                int num = this.signal_sign;
                double num2 = 0.0;
                color = Color.Black;
                bkColor = Color.White;
                color = (num == 0) ? Color.Black : ((num > 0) ? Color.White : Color.White);
                bkColor = (num == 0) ? Color.White : ((num > 0) ? Color.LightGreen : Color.Red);
                num2 = num;
                format = (num == 0) ? "" : ((num > 0) ? "Long" : "Short");
                return num2;
            }
    Oddly, the above function doesn't seem to be called anywhere else in the code.

    On the BarUpdate there is this code:
    Code:
    if (((this.var48 == 1.0) && !double.IsInfinity(this.var49)) && !double.IsNaN(this.var49))
                    {
                        this.Longstop.Set(this.var49);
                        base.BarColor = Color.LimeGreen;
                    }
                    if (((this.var48 == -1.0) && !double.IsInfinity(this.var50)) && !double.IsNaN(this.var50))
                    {
                        this.Shortstop.Set(this.var50);
                        base.BarColor = Color.Red;
                    }

    What exactly needs to be modified to be able to access the bar color for this indicator?

    #2
    Hello Kentoes,

    Thank you for your post.

    Are you trying to call the bar color set by the indicator from another script or within the indicator itself?
    Please provide details on what you are intending to do with the indicator and bar color.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      I'm trying to call the bar color in a strategy script.

      Comment


        #4
        Hello Kentoes,

        Thank you for your patience.

        We expose the color from the indicator and use Update(), then call the value in the script we wish to pull it from.
        For example, here is my indicator:
        Code:
            public class Test1 : Indicator
            {
                #region Variables
        		private Color myColor = Color.Blue;
                #endregion
        
                protected override void Initialize()
                {
        			
                }
        
                protected override void OnBarUpdate()
                {
        			BarColor = myColor;
        			
                }
        
                #region Properties
                [Browsable(false)]
                [XmlIgnore()]
                public Color MyColor
                {
        			// We need to call the Update() method to ensure our exposed variable is in up-to-date.
                    get { Update(); return myColor; }
                }
                #endregion
            }
        Here is how my strategy calls the indicator color:
        Code:
        BarColor = Test1().MyColor;
        For information on exposing variables please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=4991

        Please let me know if I may be of further assistance.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          I'm trying to do a similar thing with my indicator, which is attempting to access the PlotColors series from another indicator.

          I have followed the sampleboolseries example, but I have run into a snag. When I add my called indicator to my calling indicator -

          public class CallingIndicator : Indicator
          {
          protected override void Initialize()
          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "WGWPlot1"));
          Add(CalledIndicator());
          }
          }

          I get the compiler error -

          The best overloaded method match for
          'NinjaTrader.Indicator.IndicatorBase.Add(NinjaTrad er.Gui.Chart.Line)' has some invalid arguments

          And trying to access the PlotColors series -

          protected override void OnBarUpdate()
          {
          Print(CalledIndicator().PlotColors[0][0].ToString());
          }

          gives the compiler error -

          No overload for method 'CalledIndicator takes '0' arguments

          Now I'm guessing this has something to do with input parameters, and that Add() is creating a new instance of the indicator? My CalledIndicator has a LOT of input parameters, so doing that would be a nightmare. Do I need to specify all the values for all the input parameters in each call or is there a way around this? CalledIndiator is already included in the same chart as CallingIndicator and it has all the necessary parameters already set.

          If I'm correct in assuming that Add(CalledIndicator()) creates a new instance and therefore needs all the input parameters set, what I would really like to do is reference the instance that is already created by the chart. Is that possible?

          Thanks,
          Will.

          Comment


            #6
            Originally posted by dontpanic View Post
            Hi,

            I'm trying to do a similar thing with my indicator, which is attempting to access the PlotColors series from another indicator.

            I have followed the sampleboolseries example, but I have run into a snag. When I add my called indicator to my calling indicator -

            public class CallingIndicator : Indicator
            {
            protected override void Initialize()
            {
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "WGWPlot1"));
            Add(CalledIndicator());
            }
            }

            I get the compiler error -

            The best overloaded method match for
            'NinjaTrader.Indicator.IndicatorBase.Add(NinjaTrad er.Gui.Chart.Line)' has some invalid arguments
            You cannot Add() an indicator into another indicator. The method is being used incorrectly.
            And trying to access the PlotColors series -

            protected override void OnBarUpdate()
            {
            Print(CalledIndicator().PlotColors[0][0].ToString());
            }

            gives the compiler error -

            No overload for method 'CalledIndicator takes '0' arguments

            Now I'm guessing this has something to do with input parameters, and that Add() is creating a new instance of the indicator? My CalledIndicator has a LOT of input parameters, so doing that would be a nightmare. Do I need to specify all the values for all the input parameters in each call or is there a way around this? CalledIndiator is already included in the same chart as CallingIndicator and it has all the necessary parameters already set.

            If I'm correct in assuming that Add(CalledIndicator()) creates a new instance and therefore needs all the input parameters set, what I would really like to do is reference the instance that is already created by the chart. Is that possible?

            Thanks,
            Will.
            This link should show you how to take care of both matters.

            ref: http://www.ninjatrader.com/support/f...07&postcount=7

            Comment


              #7
              Hi,

              It may be easier if I explain what I want to do. I have CalledIndicator already installed and running in my chart. In there I have exposed some dataseries. I want to access the values in those dataseries from another indicator, is there a simple way to do that?

              I checked the link you referred me to, and I haven't tried that yet, but even so that doesnt answer the other part of my question, about the parameters. CalledIndicator has a LOT of input parameters, which I dont want to have to specify in the call to the indicator -

              protected override void OnStartUp()
              {
              yada_SMA = SMA(Close, 5);
              //etc;
              }

              In the above call, from your example, I still have to specify 'Close' and '5' as parameters, which is fine when there are only 2 parameters; my indicator has about 150 parameters. In your example, is there a way I could refer to just SMA() and assume the parameters that have already been set from the instance that has been installed in my chart? Or, more simply, as I was suggesting just refer to the exposed dataseries from the chart instance?

              Thanks,
              Will.

              Comment


                #8
                Originally posted by dontpanic View Post
                Hi,

                It may be easier if I explain what I want to do. I have CalledIndicator already installed and running in my chart. In there I have exposed some dataseries. I want to access the values in those dataseries from another indicator, is there a simple way to do that?

                I checked the link you referred me to, and I haven't tried that yet, but even so that doesnt answer the other part of my question, about the parameters. CalledIndicator has a LOT of input parameters, which I dont want to have to specify in the call to the indicator -

                protected override void OnStartUp()
                {
                yada_SMA = SMA(Close, 5);
                //etc;
                }

                In the above call, from your example, I still have to specify 'Close' and '5' as parameters, which is fine when there are only 2 parameters; my indicator has about 150 parameters. In your example, is there a way I could refer to just SMA() and assume the parameters that have already been set from the instance that has been installed in my chart? Or, more simply, as I was suggesting just refer to the exposed dataseries from the chart instance?

                Thanks,
                Will.
                That is exactly why I referred you to the code.

                You create a single named instance of the object, which you have to do regardless, with it correct constructor, with as many properties as are needed to be specified. This is done only once. You then use the named instance in all your other code. Your named instance is just that: a single object whose properties have already been defined and so need not be referenced again in code.
                Last edited by koganam; 05-19-2015, 11:48 PM. Reason: Corrected spelling.

                Comment


                  #9
                  Ok, thanks,

                  I will check again. from that example it appeared that the call also included the parameters.

                  Dave is helping me out with this as well.

                  Thanks,
                  will.

                  Comment


                    #10
                    Do you guys do 24 hour support?

                    Comment


                      #11
                      Originally posted by dontpanic View Post
                      Do you guys do 24 hour support?
                      Well, I do not work for NinjaTrader.

                      If I happen to be awake, (right now, I am running some optimization tests), then in the free cycles, I might respond to any forum questions in which I am involved.

                      Comment


                        #12
                        I appreciate it. I'm only intermediate in c#, so I don't always get these things as quickly as I would like.

                        Comment


                          #13
                          Format int as whole # not price format

                          Performing a division that ends with a division by ticksize. It provides a whole number int. Market analyzer should display it as (Price1 / price2) /ticksize = 25 but it uses the instrument price format to display it as 25.0, 25.00, 25.000 and 25.0000 depending on the instruments number of decimals even though the plot shows it as an int.


                          Any suggestions on how to format value[0] so it uses "25" as the plot and output for market analyzer?

                          Comment


                            #14
                            Hello JMont1,

                            If you already have an int value assigned to the plot, you could format the price using ToString for the market analyzer:


                            Code:
                            protected override void OnBarUpdate()
                            {
                            	Value[0] = (int)((High[0] / Close[0]) * 25);
                            } 
                            		
                            public override string FormatPriceMarker(double price)
                            {
                            	return price.ToString();
                            }
                            FormatPriceMarker can be used to format the double price in anyway you wanted. https://ninjatrader.com/support/help...ightsub=format


                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              @NinjaTrader_Jesse, I am not trying to format to price. I am trying to format to a whole number like an int.

                              so it would be some calculation that comes out to 20 or 23 or 25 but it prints depending on the instrument:


                              23.0 for GC
                              23.00 for ES
                              23.000 for DX
                              23.0000 for 6S
                              23.000000 for 6J

                              So I am trying to format it to just plain 23.

                              Thanks for your prompt response.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sun0781, Today, 05:02 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post sun0781
                              by sun0781
                               
                              Started by ronhb107, 09-12-2019, 10:09 AM
                              4 responses
                              41 views
                              0 likes
                              Last Post Mr.Trader  
                              Started by rwilliam, Today, 03:55 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post rwilliam  
                              Started by asmmbillah, Today, 03:42 PM
                              2 responses
                              7 views
                              0 likes
                              Last Post asmmbillah  
                              Started by NT-Roland, Today, 03:25 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post NT-Roland  
                              Working...
                              X