Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling a value from a custom indicator

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

    Calling a value from a custom indicator

    How do you call a value (int, bool or string) from a custom indicator to incorporate into a strategy to be used to enter or exit positions?

    Do you have to run the indicator within the strategy code or can you just call the value?

    Thanks

    Mark

    #2
    Mark, can you please clarify?

    There is a reference sample that goes over how to access an indicator's values from a strategy.

    Is that what you're looking to do?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin

      I just want to use the indicator to enter a strategy. The indicator will draw an arrow after a count is complete. I want to use this to enter or exit a trade.

      Thanks

      Mark

      Comment


        #4
        p.s. I mean enter a position in a strategy...

        Comment


          #5
          Mark, strategies don't know about arrows. You'll have to set up another method of getting that information to a strategy, like setting a plot to 1 for an up arrow (if you have directional arrows), -1 for a down arrow and 0 for anything else. You can then read these plot values from a strategy without issue.

          A quick example would be something like CurrentDayOHL(). There are three plots associated with this indicator, the open, high, and low (CurrentOpen, CurrentHigh, CurrentLow). You can read each of these values in a strategy, like this:
          Code:
          private double currentHigh = CurrentDayOHL().CurrentHigh[0];
          So for your code, you could set a single plot to whatever values you want, and then look for those values in your strategy.
          Code:
          if (myIndicator(...).Plot0[0] == 1)
          // enter long
          AustinNinjaTrader Customer Service

          Comment


            #6
            Austin

            Thanks for the explanation.

            Do I need to make reference to the indicator in the strategy anywhere to 'load' it so that the indicator updates on each bar?

            Comment


              #7
              Just one more thing.....

              what do I have to add the the indicator code to store the plot values? Presumably once the conditions to draw the arrows are reached, I add something to change the plot value but what else do I have to add?

              Cheers

              Comment


                #8
                Mark, the indicator should update on each bar, but there is function to force an update to make sure you're getting the most recent value called Update().

                I just put together an indicator real quick that sets the plot to 1 on a cross above and -1 on a cross below and 0 any other time. I also added a few comments the describe the behavior. Please take a look and let me know if you have any questions about it. The indicator is called PlotBarNumber because I was just going to have it plot the bar number, but then I decided to modify it to suit your application.
                Attached Files
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Austin

                  Thanks again. That makes sense but do I need to make reference to the indicator early in the strategy to activate it? Or do all indicators update onbarupdate automatcially?

                  Comment


                    #10
                    Mark, calling indicator in your strategy code would be enough for them to be updated with each OnBarUpdate() call, only if you expose an internal variable of the calling indicator as per the sample Austin pointed you early in the thread to, then an Update() in the property 'getter' is needed to ensure it's update to date prior to returning it's value.

                    Comment


                      #11
                      Austin

                      I have tried to get this method working using the plot method but despite copying your indicator code exactly, the MainPlot.set is not recognised. The indicator I'm trying to get this working on is ridiculously complicated unfortunately. Is there a way of just calling an interger value from an indicator? The I can simply set the interger to 1 when the arrow is drawn.

                      Thanks

                      Comment


                        #12
                        MJUK10, for exposing just a value or for example a signal series as in your case you would work with the reference sample Austin pointed you to in his post 2. For your plot example, are you sure you access the correct plot name (case sensitivity of C# included)? Also: please remove any CalculateOnBarClose setting in the called indicator.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        650 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        370 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        574 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        576 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X