Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Referencing 3rd party indicator in another indicator

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

    Referencing 3rd party indicator in another indicator

    I’m trying to use the plot values from a 3rd party indicator (already applied to my chart) as input to an indicator I am building. The vendor has so far been non-responsive to my inquiries. I can find the indicator in ChartControl.Indicators, and I can iterate through the values I’m looking for, but I can’t see a way to reference the indicator values in OnBarUpdate() without going through the ChartControl again. I’ve tried casting the IndicatorBase as Indicators.Indicators, and also as the Compiled3rdPartyAssembly type, but without success. It appears to cast, but I get “Object reference not set” error msg in OnBarUpdate() when I try to use the variable.
    The code below is how I am currently finding the ChartControl indicator in State.Historical. Do I have to run this foreach loop everytime I access the plot values in OnBarUpdate()? What am I missing? I do want to read the indicator from the chart, so that it uses the chart settings.

    else if (State == State.Historical)
    {
    if (ChartControl == null) return;
    ChartControl.Dispatcher.InvokeAsync(new Action(() =>
    {
    foreach (IndicatorBase indi in ChartControl.Indicators)
    {
    if (indi.GetType().ToString().Equals("NinjaTrader.Nin jaScript.Indicators.Compiled3rdPartyAssembly"))
    {
    Print("DispatcherTest: " + indi.GetType().ToString());
    HTindi = indi as NinjaTrader.NinjaScript.Indicators.Indicator;
    }
    }
    }));
    }


    #2
    Hi jculp, thanks for your post.

    There is no supported way of getting the indicator instances that are on the chart, I found this example of unsupported code that you could try:
    https://ninjatrader.com/support/foru...rt#post1049944

    The supported way of doing it would be making a indicator instance in your script and you would get the properties from either user input or set them as default in State.SetDefaults, we have an example here:

    https://ninjatrader.com/support/help...tm#Performance //see "Referencing indicator methods"

    Best regards,
    -ChrisL


    Comment


      #3
      Thanks for the response. I am familiar with the concepts in those posts, and have worked with them to get as far as I have with this. My vendor has responded, but unfortunately the response is negative: they do not provide a function for calling the indicator from within my own code. So I have a few more questions for increased clarity:

      1) Is the strong caution "should not be used in OnBarUpdate" (from post 1049944 referenced above) because it is inherently unstable to reference ChartControl in OnBarUpdate? Or some other reason? Like because it might take too long and interfere with timeliness of the OBU calls? Or because of the trickiness of different bar-referencing methods?

      2) I assume this issue is the same in both an indicator and a strategy. Is that correct? Or is there any relevant difference?

      3) I have actually put this code inside OnBarUpdate and run it successfully in a test case wrapped in the dispatcher call, and duplicated the values generated by the 3rd party indicator applied to the chart. What are the risks if I move forward with attempting this work-around?

      Comment


        #4
        Hi jculp, thanks for your reply.

        1. It should not be used in OnBarUpdate because it would affect the performance of OnBarUpdate.
        2. Yes this would make no difference if it were an indicator or strategy
        3. If you have this running in OnBarUpdate and it's not causing a performance issue that is fine. You should stress test it by adding multiple instances of the same indicator in multiple charts, and also add more unrelated indicators alongside it to stress test it. I can't recommend doing it though as it's not supported and if you are going to use the indicator in this way its at your own risk since it's not a normal use case.

        Best regards,
        -ChrisL



        Comment


          #5
          Thanks for the reply. As long as the concern is performance, and not thread stability, then I will move forward. And yes, I will certainly do some stress testing; good suggestions along those lines. At the moment, my primary concern is just one chart with just this one indicator. Depending on test results, I may expand that later.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          635 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          365 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          106 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X