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

Making indicator value accessable to new indicator

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

    Making indicator value accessable to new indicator

    I have written an indicator in which my calculations are done in the "if(BarsInProgress == 1" section (45 Min) and the objects generated show up in the primary series. This indicator will only work in the "CalculateOnBarClose = true" configuration.

    I would like to create an alert for this program in a second indicator. for instance a 1 min chart which would have to be in the "CalculateOnBarClose = false mode. My alert would trigger when a price crosses a line the value of which has to come from the "ifBarsInProgress ==1" section of the first indicator. The value of this line will change every 45 minutes.

    Can anyone tell me the procedure for the second indicator read the values from the first or at least lead me to an example?
    Last edited by Pete77; 12-04-2016, 09:59 AM.

    #2
    Hello Pete77,

    You can call an indicator by typing the name followed by parenthesis.
    You will be able to call values of plots that are set.

    For example if my indicator is called MyIndicator and there is only one plot you could use:

    Print(MyIndicator()[0]);


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks. In Properties I am trying to expose two variables that have been calculated in the "BarsInProgress == 1" part of my indicator but get error message. Is there any way to access these variables so they will be recognized in Properties?

      Comment


        #4
        Hello Pete77,

        I have provided a reference example demonstrating how you could reference variables calculated within another indicator.



        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thank you. I am a beginner and having trouble describing my problem.
          I see there are several ways to pass a value from Indicator 1 to Indicator 2.
          The variable (the changing value of) I am trying to make accessible to indicator 2 is calculated in and resides in the secondary series of indicator 1.(The area of BarsInProgress == 1)

          Is this not a problem? If it is, how can I make it accessible to Properties in indicator 1.?
          At present I am getting an error message when I try to expose the variable in Properties.
          Last edited by Pete77; 12-05-2016, 08:03 PM.

          Comment


            #6
            Hello Pete77,

            To reference a indicators values from another indicator please see the reference example, Exposing Indicator Values that are not plots at the following link,



            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              When I try to expose a variable in Properties I get the following attached error message. Can you explain?
              Attached Files
              Last edited by Pete77; 12-07-2016, 09:13 AM.

              Comment


                #8
                Hello Pete77,

                If you’d like to share a copy of the strategy you’re running, I can take a look and see if anything jumps out.

                I look forward to your reply.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  recursive properties

                  Hi Alan

                  Sorry for late reply. I will attach a barbones version of my program. The program works well and it has actually helped with my trading. I wrote it very quickly but have struggled for weeks to create an alert for same.

                  The program works only with CalculatedOnBarClose= true so I assume the I need a hosted program that will calculate on ticks on which to create the alert. My problem is that I can't access the two variables that I need to do the alert. When you see the code you can probably see why.

                  By the way I am very much a novice with C# and NinjaScript. For example I can't find any explanation of "set",What is this used for anyway?

                  Pete
                  Attached Files

                  Comment


                    #10
                    Hello Pete77,

                    At the bottom of your indicator you have public double bp commented out. If you were to capitalize the first letter bp to Bp you should not receive this error.

                    If you add this under #region properties at the bottom of your indicator Test,

                    [Browsable(false)]
                    [XmlIgnore()]
                    public double BP
                    {
                    get { return bp; }
                    }

                    From your strategy, you’ll be able to reference BP via adding the following under Initialize,

                    Add(Test()); //Calling the name of your indicator

                    Then under you could then reference BP under OnBarUpdate(), for example,

                    if(Test().BP>1)
                    {
                    DrawArrowDown( "My Down arrow" + CurrentBar, false, 0 , High[0], Color.Red);
                    }

                    Which will draw an error anytime BP as calculated by your indicator is over 1.

                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks very much AlanP, that is an example I can understand!

                      I am having some trouble the hosted indicator recognizing Add(Test()); I get error:

                      Indi Argument '1': cannot convert from 'method group' to 'NinjaTrader.Gui.Chart.Line'
                      The best overloaded method match for 'NinjaTrader.Indicator.IndicatorBase.Add(NinjaTrad er.Gui.Chart.Line)' has some invalid argument
                      Last edited by Pete77; 12-21-2016, 10:17 AM.

                      Comment


                        #12
                        Hello Pete77,

                        The issue is you are trying to Add an indicator from within another indicator, which you cannot do. If you were to use the code inside a strategy you will not have a problem, or you should copy the logic from one indicator into the other indicator that would work too.

                        Please let us know if you need further assistance.
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          OK, so now using strategy instead of indicator to access Test.cs and bp value and create my alert. I have a couple problems, one is shown on the attached picture.

                          "bp" in my program is high plus low plus close /3 of the closing 45 minute bar so it changes value every 45 minutes. I understand it is a variable but it sounds like it needs to be a data series. Can you help me with this? Thanks
                          Attached Files

                          Comment


                            #14
                            Hello Pete77,

                            If you were to use if(CrossAbove(Close, Test().BP,1)) rather than Close[0], are you able to compile?

                            I look forward to your reply.
                            Alan P.NinjaTrader Customer Service

                            Comment


                              #15
                              Yes, thanks very very much. I assume that the line will now give me "if price crosses above Test().Bp", then do something,

                              I have one other problem and hopefully can wrap this up:

                              In my main program, as opposed to the test program, in its strategy when I "Add(UncleFrank())" under initialize for example I get the error message "NinjaTrader indicator Uncle Frank is a type but it is used like a variable"

                              Can you help me with that? I have attached the strategy.
                              Attached Files
                              Last edited by Pete77; 12-27-2016, 12:32 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,610 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              19 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              16 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X