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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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 CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,265 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X