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

Passing values from indicator to strategy

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

    Passing values from indicator to strategy

    I would like to be able to pass a set of values back from an indicator to a strategy. e.g. if my strategy detects a entry signal and calculates optimum profit and loss targets, I'd like the strategy to use those values to set the stop loss and profit targets before entering the trade. Can anybody point me to an example of how to do this?

    Thanks,

    #2
    don't know exactly about that. But I can tell you that in any class you can use Getters and Setters to open up private variables and set any value you want. As long as the object is instantiated, you can do it. In the case of indicators, they all seem to be instantiated at start (I think) and you have access to them from your API, so yes, you should be able to do that.

    Comment


      #3
      Hi Owlman, you can check this reference sample to expose the needed values in your indicator for access - http://www.ninjatrader-support2.com/...ead.php?t=4991
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Still a bit confused

        Thanks to you both for your responses.

        I discovered the example you quoted Bertrand, and put it into my indicator. After a LOT of mucking around with names having the wrong capitalisation, I eventually got it to the point where there is only one error message left. This one says the "Property or indexer 'NinaTrader.Indicator.myIndicator.myParameter' cannot be assigned to - it is read only". I've copied the code in the example as near as I have been able to determine so far, so not sure why I'm getting this error message.

        Anyway, I'll keep playing.

        Thanks again for the incredibly rapid response, and expert advice and guidance for this beginner C# programmer!

        Cheers,
        Ian

        Comment


          #5
          Ian,

          Please provide the code you have. Thank you.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            All good now... ;-)

            Hi Josh,

            I've got it working now. Yet another capitalisation error! I had defined the variable with a lower case first character, but referred to it with an upper case first character in the code. But I guess that is referring to the definition in the Properties, which must have the opposite capitalisation to the variable in the Variables section. (I learnt that the hard way a few months back).

            Thanks again,
            Ian

            Comment


              #7
              please post example

              I found the reference sample SampleBoolSeries which illustrates "exposing indicator variables that are not plots."

              (see tutorial article at http://www.ninjatrader-support2.com/...ead.php?t=4991)

              The sample creates a BoolSeries object called bullIndication. I tried to access the variable from a strategy script as follows:

              NinjaTrader.Indicator.SampleBoolSeries.bullIndicat ion()[0]

              The compiler reports that "SampleBoolSeries.bullIndication is inaccessible due to its protection level." What is the correct way to access it?

              Perhaps the answer to this question should be included in the above article.
              Last edited by dave_b_quickc; 04-17-2009, 01:22 PM.

              Comment


                #8
                Dave,

                If you are trying to access the property you need to access the public property which is not the lower cased version.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  example?

                  I have tried:
                  NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion()[0]
                  NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion[0]
                  NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion()
                  NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion

                  All variations I've tried are rejected. Is there an example somewhere?

                  Comment


                    #10
                    Dave,

                    Please outline exactly what you are trying to do and from where. In the reference sample you will see how to access the exposed value from the strategy file.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks!

                      I was just trying to learn how to access the exposed indicator value from a strategy file. I did not know that there was a sample strategy file associated with the sample indicator file. You have answered my question by pointing me to where I could find the answer. Thanks!

                      Comment


                        #12
                        Accessing indicator variable for a strategy

                        I need to access the "dir" variable from the ZigZagUTC indicator found in the NinjaScript Filesharing/ Indicators section.
                        I simply wish to draw a Up/Down arrow on a chart from a strategy accessing the "dir" value.
                        I looked at the SampleBoolSeries example and can't seem to correlate it.
                        Any help would be appreciated...

                        It is listed in the #region Variables section as below:

                        #region Variables
                        // Wizard generated variables
                        privateint span = 2; // Default setting for Span
                        privatebool useHiLo = true; // Default setting for UseHiLo
                        private Color zigZagColor = Color.Green; // Default setting for zigZagColor
                        privateint show = 3; // Default setting for Show
                        // User defined variables (add any user defined variables below)
                        private DataSeries hi, lo;
                        privatebool drawlines, showdots;
                        privateint linewidth = 2;
                        // Useful public properties
                        publicint dir; // direction of current zigzag trend, 1=up, -1=down

                        It is also shown under the "protected override void Initialize()" section as dir = 0;

                        And then again under the "protected override OnBarUpdate()" section as it is set to dir = 1 or dir = -1

                        Comment


                          #13
                          Randwulf,

                          Please look at the indicator from the SampleBoolSeries zip file. You want to keep the variable as private and just create a public variable down in the Properties region that access the private variable. Then in your other scripts you access the public variable.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Thx 4 the reply Josh..

                            I changed the variable "dir" to private and in the "Properties" section I added:

                            [Browsable(false)]
                            [XmlIgnore()]
                            public int dir
                            {
                            get { return dir; } // Allows our public dir int to access and expose our interal dir int
                            }

                            However, I get a compile error that "... already contains a definition for 'dir'"

                            I know it probably appears obvious to most but, as close as I probably am to the solution, I just can't seem to get the last little bit.... Help

                            Edit: Figured it out
                            The line above "public int dir" should have been "public int Dir"

                            Forgot to make it capitalized.
                            Thx again however for the earlier assistance
                            Last edited by Randwulf; 05-30-2009, 04:59 AM.

                            Comment


                              #15
                              Trouble using ZigZagUTC

                              I am a new member; just trying to figure out how to simply print ZigZag points and direction. But when I use following code, I get all 0, not a single 1 or -1 as it should. What am I doing wrong here?

                              Print(ZigZagUTC(3,6,true,Color.Blue).dir);

                              If possible, How will I get past points marked by ZigZag?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by WHICKED, Today, 12:56 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cre8able, Today, 01:16 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post cre8able  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              2 responses
                              47 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by WHICKED, Today, 12:45 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by samish18, Today, 01:01 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post samish18  
                              Working...
                              X