Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing Indicators on the Chart in Compiled Assembly

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

    Accessing Indicators on the Chart in Compiled Assembly

    I try to create an indicator that can access indicators already on the chart. It works well until I create a compiled assembly and install it on other Ninja installations. I followed the instructions described in the 'Considerations For Compiled Assemblies' section of the manual and used dynamic type.

    The minimal example I can come up is something like the following code in OnStateChange function (I attached the full indicator code as well):
    Code:
    else if (State == State.Historical) {
        if (ChartControl != null) {
            try {
                foreach (dynamic i in ChartControl.Indicators) {
                   Type t = i.GetType();
                   Print(t.FullName);
                }   
            } catch (Exception e) {
                Print(e.ToString());
            }
        }
    }
    The compiled assembly raises the following error if any indicator which not part of the compiled assembly like the standard default indicators coming with Ninja is on the chart:

    Code:
    Microsoft.CSharp.RuntimeBinder.RuntimeBinderInternalCompilerException: An unexpected exception occurred while binding a dynamic operation
    at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind( DynamicMetaObjectBinder payload, IEnumerable`1 parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)
    at Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(DynamicMetaObjectBinder action, RuntimeBinder binder, IEnumerable`1 args, IEnumerable`1 arginfos, DynamicMetaObject onBindingError)
    at Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
    at System.Dynamic.DynamicMetaObject.BindInvokeMember( InvokeMemberBinder binder, DynamicMetaObject[] args)
    at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
    at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
    at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
    at NinjaTrader.NinjaScript.Indicators.TestIndicator1.OnStateChange()
    My understanding is that the runtime cannot resolve the type of dynamic type i at the i.GetType() like because its type exists in a different assembly. Could you give me some hints on how should I resolve this issue?

    Ninja Version: 8.0.24.1 64-bit
    Attached Files

    #2
    Hello szferi,

    Thank you for the post.

    That would be expected in this situation, the dynamic type is really only useful for drawing objects like shown in the DrawObjects example in the help guide. For indicators you can cast to IndicatorBase instead of using dynamic if you are trying to collect generic indicator properties from those items. Custom indicator properties would be problematic to access, you can access base properties like the plots collection.

    Code:
    foreach (IndicatorBasei in ChartControl.Indicators) {
    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you! Indeed, I'm looking to access the Custom indicator properties (mostly the Series<double> typed once, which is not part of the Values array, and parameter properties) using reflection. Is there any way - even a complicated one - to access them? If yes, a hit for a direction would be appreciated; thanks.

      Comment


        #4
        Hello szferi,

        Not that I am aware of. The indicators in question would need to use AddPlot and then expose the data in that way.

        Please let me know if I may be of further assistance.

        Comment


          #5
          Are the Series objects made available as public properties of the class?

          The public properties of a class are absolutely available through reflection.
          (For ex, this is how Bloodhound works)

          Google is your friend.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          599 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          344 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          558 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          557 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X