• 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

MySharedMethods: pass Highs/Lows,..., Instrument

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

    MySharedMethods: pass Highs/Lows,..., Instrument

    Hi, there is a reference to mySharedMethods script that can be placed in AddOns folder. I got that to work https://ninjatrader.com/support/foru...956#post733956

    How do you extend this file to allow it to use things like Highs, Lows without having to pass them like following all the time,
    ISeries<double> high, ISeries<double> low
    tedious to write and as it seems these objects cannot be passed by reference, possibly a performance hit. I like them available automatically without needing to invoke them in every method.

    Also how do I pass other important things like:
    Bars
    Instrument

    Thanks a lot. I created a new topic since the Subject of the referenced topic is non-related.

    #2
    Hello stevenev1,

    Thank you for your post.

    The link provided is a demonstration of using static in C#, this is a concept which you can use to expose items in C#. As this is a C# concept, I generally suggest to also read more about this subject from external C# resources as this is a complex subject. You can use a search engine to look up "static in C#" for some more information.

    This sample does not allow you to use the calling type directly like you are asking so you would need to pass in any objects you want to use as a parameter to that method. This sample is created this way specifically to share between an indicator and a strategy, is that your requirement as well or is this being used to share between two of the same type? The example you have linked cannot be extended to avoid passing in parameters you will need to pass in some values at the least. A partial class could avoid that requirement however that is limited to the same type such as two indicators.

    To pass any other types of objects, you would just need to create a parameter in the methods overloads (.... ) which accept the type you want to pass such as Bars.
    Code:
    MyMethodName(Bars myBars)
    For this question, I would also suggest researching C# Methods and Static in C# from external resources as that will help further explain how this is working along with the structure needed to form methods in C#.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello stevenev1,

      ... is that your requirement as well or is this being used to share between two of the same type? The example you have linked cannot be extended to avoid passing in parameters you will need to pass in some values at the least. A partial class could avoid that requirement however that is limited to the same type such as two indicators.

      To pass any other types of objects, you would just need to create a parameter in the methods overloads (.... ) which accept the type you want to pass such as Bars.
      Code:
      MyMethodName(Bars myBars)
      Hi Jesse, thank you very much for detailed explanation. I just need to share common methods between indicators (not indicators and strategies).

      1.) Can you please provide a sample of a partial class that allows indicators to call common methods without needing to pass parameters such as High, Low. myPrint below is a good example. I use it in all my scripts and I wish for it to be in a common file.

      2) I very much appreciate the example MyMethodName(Bars myBars)

      I started with NT7. I had UserDefinedMethods and it was a simple matter to write methods in it, and everything was available. In NT8, no one has been able to tell me how I can share a simple method like the following across indicators, so I don't have to rewrite it or pass parameters. I would think I am no alone in needing to store common methods in a shared place without need to pass extensive list of parameters?

      private void myPrint( string Msg ) {
      Print( "[" + Instrument.FullName + "] " + Msg + " " + Time[0] );
      }
      Last edited by stevenev1; 03-15-2019, 12:05 PM.

      Comment


        #4
        Hello stevenev1,

        Thank you for your reply.

        Yes, in this case, using a partial class is much more simple because you can make a partial class of the base Indicator type which inherits the items you are using. UserDefinedMethods is just a partial class, this is the same concept NT8 just doesn't include that file any longer because you can just create this structure in a file named what you want.

        To start, create a new indicator and give it any name.
        Once the file opens, remove all of the code leaving only the namespace and using statements.
        In the namespace define a partial class:

        Code:
        namespace NinjaTrader.NinjaScript.Indicators
        {
            public partial class Indicator {
        
            }
        }
        You can then define methods or other items here:

        Code:
        namespace NinjaTrader.NinjaScript.Indicators
        {
            public partial class Indicator {
                public double MyCalcMethod(){
                    return Close[0];
                }
            }
        }
        In the indicator, you can just call the method:

        Code:
        protected override void OnBarUpdate()
        {
            Print(MyCalcMethod());
        }
        Keep in mind you need to include this file with your exports, and also this can be problematic if you plan to export as compiled assemblies in separate assemblies.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          Your solution worked to perfection. Kudos to you and thank you. FYI, I have been chasing this solution for a year (as one can see from my prior posts), and finally you provided me the perfect answer. This issue was the single reason I was staying with NT7, and now I am fully committed to NT8 - a much improved software I hope others benefit from it as well.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by deblanka, Today, 08:56 AM
          0 responses
          3 views
          0 likes
          Last Post deblanka  
          Started by Boonfly8, Yesterday, 12:30 PM
          7 responses
          18 views
          0 likes
          Last Post sledge
          by sledge
           
          Started by Sohal, Today, 05:02 AM
          2 responses
          9 views
          0 likes
          Last Post techmint  
          Started by danitralla, Today, 03:33 AM
          0 responses
          5 views
          0 likes
          Last Post danitralla  
          Started by yeshujbp, Today, 12:37 AM
          0 responses
          14 views
          0 likes
          Last Post yeshujbp  
          Working...
          X