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

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 DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Started by alifarahani, Today, 09:40 AM
      6 responses
      41 views
      0 likes
      Last Post alifarahani  
      Working...
      X