Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access to the indicator through reflection

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

    Access to the indicator through reflection

    Code:
    Indicator ind=SMA(14);
    This code works fine
    Now I'm trying to do the same using reflection (I don't know the name of the indicator)
    Code:
    Type type=Assembly.GetExecutingAssembly().GetType("NinjaTrader.NinjaScript.Indicators.Indicator");
    MethodInfo mi = type.GetMethod("SMA",new Type[] { typeof(Series<double>), typeof(int) });
    Object obj = Activator.CreateInstance(type);
    Indicator ind2=(SMA)mi.Invoke(obj, new object[] { BarsArray[0],14 });
    The object is normally created and has the same data buffer ( ind.Value.Length=ind2.Value.Length )
    but when I try to access the data
    Code:
    double d=ind2[0];
    I get error
    'SMA' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state

    Can you help me with this?

    Or maybe there is another way to access the indicator without knowing its name in advance?

    #2
    Hello jshapen,

    Using reflection would be outside of what is supported by NinjaTrader Support, however, this thread will remain open for any community members that would like to assist.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      For those who interested in using reflection. You don't need activator, you just invoke NT generated methods:

      Code:
      using System.Reflection;
      
                      Type type = Assembly.GetExecutingAssembly().GetType("NinjaTrader.NinjaScript.Indicators.PriceActionSwing.PriceActionSwingOscillator");
                        MethodInfo methodInfo = type.GetMethod("PriceActionSwingOscillator", new Type[] { typeof(SwingStyle), typeof(int), typeof(int), typeof(bool), typeof(Show), typeof(bool), typeof(bool), typeof(bool), });
      
      
                      if (methodInfo != null)
                      {
                          PriceActionSwingOscillator2 = (PriceActionSwingOscillator)methodInfo.Invoke(this, new object[] { SwingStyle.Ticks, 1, 1, false, Show.Trend, true, false, true });
                          Print(PriceActionSwingOscillator2.RTUpTrend[1]); //indicator's iseries
                      }
      Last edited by Leeroy_Jenkins; 02-24-2023, 02:20 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      566 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X