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

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()
                    {[INDENT]// create f 3rd party indicator class
                    myTriedPartIndicator_Class = new NinjaTrader.Indicator. TriedPartIndicator();
                    //...
                    [/INDENT]
                    4. Add similar code to OnBarUpdate():
                    Code:
                    protected override void OnBarUpdate()
                    {[INDENT]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();
                    }
                    //...
                    [/INDENT]
                    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 maybeimnotrader, Today, 05:46 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post maybeimnotrader  
                    Started by quantismo, Today, 05:13 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post quantismo  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    8 responses
                    166 views
                    0 likes
                    Last Post jeronymite  
                    Started by cre8able, Today, 04:22 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post cre8able  
                    Started by RichStudent, Today, 04:21 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post RichStudent  
                    Working...
                    X