Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I want to share results / values between two different indicators.

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

    I want to share results / values between two different indicators.

    Hello

    I want the calculations to be done by the logic of an indicator A and that the results can be used in another indicator B, without calculating them again, since there are common values that I want to reuse.

    I did something similar to that but it doesn't work for me.

    INDICATOR A:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class IndicatorA : Indicator
        {​
          private Series<double> serie1;
    
           OnStateChange()
           {
               serie1 = new Series<double>(this, Maximu...bars....Infinite);
           }
    
    
           protected override void OnBarUpdate()
           {
               // Calculations stored within the serie1
              serie1[0] = ......;
           }
    
    
        #region Properties
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> Serie1_output
        {
            get { return serie1; }
        }


    INDICATOR B:

    Code:
    ​
    
    
    protected override void OnBarUpdate()
    {
              Print(string.Format("Indicator A output = {0} ", IndicatorA().Serie1_output[0]);
    
    }
    ​



    In INDICATOR B,... I only see zeros

    What is my mistake ?

    Thank you in advance​

    #2
    Hello trader2022ne,

    Thank you for your post.

    It does appear that you have followed the steps demonstrated in the reference sample "Exposing indicator values that are not plots" which may be found here:


    While I don't suspect it is the cause of the zeros for output, I do suspect that you need the parenthesis in the XmlIgnore section of the Properties region for Serie1_output in IndicatorA:
    [XmlIgnore()] --> remove the parenthesis: [XmlIgnore]

    As for the unexpected results of only seeing zeros in Indicator B, I recommend adding Print() statements to debug your code. Please test with Indicator A and print the output of Serie1_output and then test with prints inside of Indicator B. Be sure to also check the NinjaScript Output window and the Log tab of the Control Center for any error messages. For more information about using prints to debug your code:


    Please let us know if we may be of further assistance.

    Comment


      #3
      Hello NinjaTrader_Emily

      Thank you, now this arrangement of indicators is working. However, my doubt is:

      As I see or understand, it is doing the calculations usually done by A but within B,.... again,
      and this is not what I want, because in some cases, both indicators are in the same chart and in other cases they are not,
      and calculating twice some things in common is what I want to avoid.

      Does NT8 provide any way to avoid this?​
      (Forgive my ignorance)

      Thank you in advance​.

      Comment


        #4
        Hello trader2022ne,

        Thank you for your reply and the clarification.

        There is no way to avoid this; whether you have both indicators applied to the same chart or only one, each indicator will be a separate instance from the other. If both indicator A and indicator B are on the same chart, the calculations inside of indicator B that obtain indicator A values will come from a different instance of the indicator than the indicator A that already exists on the chart.

        I hope this helps to clarify. Please don't hesitate to reach out if we may be of further assistance.

        Comment


          #5
          Hi,

          I was just having the same question more or less

          I think it is the same, but here is my question:
          I want to have, i.e. 2 indicators in a 5 minute chart, another 2 indicators in a 30 minute chart and another 2 in a 1 hour chart.

          Is there a way, that every of these indicators "export" a signal to an external common indicator or addon or something?
          In this external "indicator", I would have different signals from these 2 indicators from 3 different charts, and depending on all these signals it would take a decission to place an order or not.

          Is it somehow possible?

          Thanks!

          Comment


            #6
            Originally posted by artson View Post
            Hi,

            I was just having the same question more or less

            I think it is the same, but here is my question:
            I want to have, i.e. 2 indicators in a 5 minute chart, another 2 indicators in a 30 minute chart and another 2 in a 1 hour chart.

            Is there a way, that every of these indicators "export" a signal to an external common indicator or addon or something?
            In this external "indicator", I would have different signals from these 2 indicators from 3 different charts, and depending on all these signals it would take a decission to place an order or not.

            Is it somehow possible?

            Thanks!
            The best approach here would be to write a multi time frame indicator that combines all of those timeframes in one indicator, actually as you want to place orders it would be best to create a multi time frame strategy. If you are not familiar with MTF coding, please take the time to completely review the help guide section here: https://ninjatrader.com/support/help...nstruments.htm

            Comment


              #7
              Originally posted by artson View Post
              Hi,

              I was just having the same question more or less

              I think it is the same, but here is my question:
              I want to have, i.e. 2 indicators in a 5 minute chart, another 2 indicators in a 30 minute chart and another 2 in a 1 hour chart.

              Is there a way, that every of these indicators "export" a signal to an external common indicator or addon or something?
              In this external "indicator", I would have different signals from these 2 indicators from 3 different charts, and depending on all these signals it would take a decission to place an order or not.

              Is it somehow possible?

              Thanks!
              Hello artson,

              Thanks for your note.

              As mentioned by Tasker-182, it may be more simple to add the required data series into the same script. That way you can calculate the 5-minute, 30-minute, and 1-hour values for the two indicators within the same script and have those values be accessible to your Strategy. This would still use the idea from the sample "Exposing indicator values that are not plots" linked previously:


              Another option would be to add these series to the Strategy directly and reference the indicator values from within the strategy.

              Either way, to add the 5-minute, 30-minute, and 1-hour data series to the indicator for inputs to the indicator, you would need to use AddDataSeries():


              You could then refer to the BarsArray or BarsInProgress as needed:



              These ideas are explained in the following page, more specifically in the section "Using Bars Objects as Input to Indicator Methods​:"


              Please let us know if we may be of further assistance.

              Comment


                #8
                Hi,

                I continue trying to solve this problem.

                What you were proposing was not too valid, because, for example, I do som calculations on 1 minute TimeFrame for the recent bars, where I do not need too many loaded historic bars, but I also need other indicators from high TimeFrame where I really need a lot of loaded bars.
                I know how to use different DataSeries in an indicator, but I don't want to load 200 days in 1 minute Data Series...

                I've found this post, where they do a loop through all drawn objects:



                This could be a way of giving information from an indicator in one chart to the other charts, through global objects.

                I've tested the example in this post, but the global objects, whose name begins with "@" are not recognised in the:
                else if (draw is DrawingTools.Rectangle) loop.
                In the first loop they are found as rectangle.

                Once I've found a Line or a Rectangle, is it possible to find its coordinates??
                Do you have an example, how I can work later with a found object?

                Thanks!

                Comment


                  #9
                  Hello artson,

                  Thank you for your note.

                  I was able to locate the following threads that might help to achieve what you are looking for. Here is an example of looping through indicators in order to access their values:
                  Hi, Is it possible to acces and get the value of all Indicators, that are in a Chart? So, if I have an indicator, from which I don't know the code, can I get


                  Here is a different sample where an add-on is created and uses static variables that may be shared between multiple scripts:


                  I appreciate your patience. Please let us know if we may be of further assistance.

                  Comment


                    #10
                    Thanks Emily,

                    Thanks for your links.

                    Really, I think my problem is other: I do not need to jump into indicators.
                    What I need ist to jump through the drawn objects (mostly lines and rectangles), which were globaly drawn in indicators at other charts:

                    I'm in a 1' chart, only 2 days loaded, and I want to read the lines which were drawn (isglobal = true) in an indicator at a chart 240' with 100 days loaded.
                    No DrawingTool line, only indicator lines.

                    How can I access to the line price? (lines will most of them be horizontal lines.
                    The same for rectangle.

                    Thanks again!!!!

                    Comment


                      #11
                      Hello artson,

                      Thank you for your reply.

                      There is a snippet on the draw objects page for drawing tools related to looping through draw objects to find specific objects:


                      Code:
                      protected override void OnBarUpdate()
                      {
                        // Loops through the DrawObjects collection via a threadsafe list copy
                        foreach (DrawingTool draw in DrawObjects.ToList())
                        {
                          // Finds line objects that are attached globally to all charts of the same instrument
                          if (draw.IsGlobalDrawingTool && draw is DrawingTools.Line)
                          {
                              DrawingTools.Line globalLine = draw as DrawingTools.Line;
                      
                              // Changes the line color and prints its starting and end points
                              globalLine.Stroke.Brush = Brushes.Black;
                      
                      
                              Print("Start: " + globalLine.StartAnchor.SlotIndex + " End: " + globalLine.EndAnchor.SlotIndex);
                          }
                      
                          // Finds non-global line objects
                          else if (draw is DrawingTools.Line)
                          {              
                              // Indicates if this is a manually drawn or script generated line
                              Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.IsUserDrawn);
                          }
                        }  
                      }
                      ​
                      Horizontal lines have two anchors, StartAnchor and EndAnchor, as listed here:


                      IDrawingTools also have ChartAnchor properties that may be accessed, such as the <ChartAnchor>.Price:


                      If you wanted to loop through and print the price of the StartAnchor for all global horizontal lines, it could look like this:

                      Code:
                      protected override void OnBarUpdate()
                      {
                        // Loops through the DrawObjects collection via a threadsafe list copy
                        foreach (DrawingTool draw in DrawObjects.ToList())
                        {
                          // Finds horizontal line objects that are attached globally to all charts of the same instrument
                          if (draw.IsGlobalDrawingTool && draw is DrawingTools.HorizonalLine)
                          {
                              // prints the price of the StartAnchor for each line
                              Print("StartAnchor price: " + draw.StartAnchor.Price);
                          }
                        }  
                      }​
                      Please feel free to reach out with any additional questions or concerns.

                      Comment


                        #12
                        Ok, Thanks!

                        I was reading another post and I could do it.

                        When trying to go through the global lines, I have to first load the indicator in my chart, then jump to the other chart where the lines will be drawn, there apply the indicator (as if a new bar was created) and then come back to the chart where I'm looping throught the global lines....

                        I think so I can go through information (in form of lines and rectangles, or even Text!!) created in other charts!!

                        Thanks again!

                        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
                        577 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X