• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get dataseries of third party indicator

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

    Get dataseries of third party indicator

    I have a requirement to get DataSeries of third party indicators.
    Am using the below code to convert an Indicator to DataSeries

    Code:
    Type type = base.GetType();
    MethodInfo mi = type.GetMethod("SMA", new Type[] { Type.GetType("System.Int32") });
    DataSeries dataSeries  = new DataSeries((IndicatorBase)mi.Invoke(this, new object[] { 14 }));
    With the above code I could get DataSeries for Ninja's inbuilt indicators(like SMA,EMA etc) but I could not get DataSeries for third party indicators(eg, KPMWAP) even though it is listed in Indicator window of NinjaTrader.

    I did the same for KPMWAP indicator, ( Note that GetTypeFromAllAssemblies() is a method which loop through all assemblies and return Type). In the below code, type and mi is not null but cannot convert into DataSeries

    Code:
    Type type = this.GetTypeFromAllAssemblies("NinjaTrader.Indicator.KPMWAP");
    MethodInfo mi = type.GetMethod("KPMWAP", new Type[] { Type.GetType("System.Int32") });
    DataSeries dataSeries  = new DataSeries((IndicatorBase)mi.Invoke(this, new object[] { 3 }));
    which showed the below error

    Object does not match target type.

    So what I did is, I created instance of KPMWAP and used that object instead of this in method invoke

    Code:
    Type type = this.GetTypeFromAllAssemblies("NinjaTrader.Indicator.KPMWAP");
    object objKP = Activator.CreateInstance(type);
    MethodInfo mi = type.GetMethod("KPMWAP", new Type[] { Type.GetType("System.Int32") });
    DataSeries dataSeries  = new DataSeries((IndicatorBase)mi.Invoke(objKP, new object[] { 3 }));
    It doesn't throw an error, but in debug mode when I pointed mouse over dataSeries variable, in Count, its showing the below message(I have added an image as attachment)

    'dataSeries.Count', threw an exception of type 'System.NullReferenceException'

    What is the best way to get the DataSeries of third party indicator?
    Attached Files
    Last edited by SagarAliasJacky; 03-05-2015, 04:58 AM.

    #2
    SagarAliasJacky, this is unfortunately not something we could fully support here, however I think what probably will affect your outcome here is the obfuscation applied to the third party libraries. You might want to try it out on a non-obfuscated assembly of one of your scripts.

    The best way would still be simply calling the third party indicator method directly.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      SagarAliasJacky, this is unfortunately not something we could fully support here, however I think what probably will affect your outcome here is the obfuscation applied to the third party libraries. You might want to try it out on a non-obfuscated assembly of one of your scripts.

      The best way would still be simply calling the third party indicator method directly.
      How do I call Third-party indicator directly?

      Comment


        #4
        Just type in KPMWAP in your editor and followed by a ( - if there's an accessible method Intellisense should point the way to the expected parameters to call it.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Just type in KPMWAP in your editor and followed by a ( - if there's an accessible method Intellisense should point the way to the expected parameters to call it.
          I tried that. It has parameter as length. I tried KPMWAP(3)[0] but its showing message "'NinjaTrader.Indicator.KPMWAP' is a 'type' but is used like a 'variable'". What is the possible way of handling this?

          Comment


            #6
            I'm thinking this is likely a reference issue, Is a reference to the needed dll properly added to the editor's list of references?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              I'm thinking this is likely a reference issue, Is a reference to the needed dll properly added to the editor's list of references?
              No. I haven't. I used to add new dll's to the custom folder of Ninja. I use Reflection to get type and create instance instead of adding reference in Ninja. I am able to create instance and assign Input to the instance, but am not able to get its value. Below is the code I have tried so far(using Reflection)

              Code:
              Type type = this.GetTypeFromAllAssemblies("NinjaTrader.Indicator.KPMWAP");
              object objKP = Activator.CreateInstance(type);
              MethodInfo mi = type.GetMethod("KPMWAP", new Type[] { Type.GetType("System.Int32") });
              DataSeries dataSeries  = new DataSeries((IndicatorBase)mi.Invoke(objKP, new object[] { 3 }));
              I also tried by fixing a break point in OnBarUpdate() and typing the below code in Immediate window, but didn't work that too

              Code:
              KPMWAP(3)[0]

              Comment


                #8
                Sorry, I would then be able to provide a workaround for dynamically getting that value. Please use the documented way to add a reference to access those study values programmatically in your scripts.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  If my memory is correct KPMWAP is a KwikPop indicator. They intentionally do NOT give you access to their data series as they want you to purchase their proprietary "Black Box Builder" to create and backtest strategies.

                  Comment


                    #10
                    SagarAliasJacky,

                    I had the same question for some time. I believe I got it right now.

                    To call a 3rd party Indicator (TriedPartIndicator), which you have just .dll, and not the .cs code, I do the following steps:

                    1. Add the dll to the References (right click on your indicator source).

                    2. Add similar code to variables area:
                    Code:
                    // declare 3rd party indicator class
                    private NinjaTrader.Indicator. TriedPartIndicator myTriedPartIndicator_Class = null;
                    // declare working instance of 3rd party indicator values 
                    private NinjaTrader.Indicator. TriedPartIndicator myTriedPartIndicator_Values = null;
                    3. Add similar code to Initialize():
                    Code:
                    protected override void Initialize()
                    {
                    // create f 3rd party indicator class myTriedPartIndicator_Class = new NinjaTrader.Indicator. TriedPartIndicator(); //...
                    4. Add similar code to OnBarUpdate():
                    Code:
                    protected override void OnBarUpdate()
                    {
                    if (myTriedPartIndicator_Values == null) { // this will call the indicator with the params on the first time myTriedPartIndicator_Values = myTriedPartIndicator_Class.TriedPartIndicator(Param1, Param2...); } else { // this will update the indicator values any other time myTriedPartIndicator_Values.Update(); } //...
                    5. Reference any indicator values using
                    Code:
                      DataSeries theValues = myTriedPartIndicator_Values.AnyValues;
                    Hope this can help.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by mittie3, Today, 03:33 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post mittie3
                    by mittie3
                     
                    Started by Againmain1, Today, 03:04 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post Againmain1  
                    Started by tonytimpa, Today, 01:33 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post tonytimpa  
                    Started by kiwidtrader, Yesterday, 11:49 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post kiwidtrader  
                    Started by jmahon, Yesterday, 11:44 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post jmahon
                    by jmahon
                     
                    Working...
                    X