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

UserDefinedMethods from NT7 to NT8

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

    UserDefinedMethods from NT7 to NT8

    Hello

    I'm trying to transfer my code from NT7 to NT8.

    On my indicator UserDefinedMethods file I used to have the following code:

    Code:
    namespace NinjaTrader.Indicator
    {
        public class MyClass
        {
              // .....
        }
    }
    and

    Code:
    namespace NinjaTrader.Indicator
    {
        partial class Indicator
        {
            public void MyFunction()
            {
                  // .....
            }
        }
    }
    Where those 2 code parts should be transferred to on NT8?


    Thanks

    #2
    Hello kiss987,
    Thanks for your post.

    You will want to copy/paste the entire Indicator namespace into a .cs file placed in the Addons folder.

    Please see the sample script at the following forum post that demonstrates.


    Please let me know if you have any questions.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply,

      Can I use objects such as TickSize, Highs, etc. from:

      public partial class MySharedMethods : NinjaTrader.NinjaScript.AddOnBase
      {
      }

      I wan only able to do so from within:

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator
      {

      and:

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy
      {


      However, I do not want to duplicate my code for strategies and indicators.

      Comment


        #4
        Hello kiss987,

        You would need to add a bars request to access that information inside the addon class. Please see the following post that includes 2 samples on implementing a bars request.



        Help Guide- BarsRequest

        Please let me know if you have any questions.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          I'm not sure I'm following your answer. I have the following code:

          public double ReturnTickSize()
          {
          return (TickSize);
          }

          which I want to transfer it to my add on, so it will be available for both indicators and strategies:

          namespace NinjaTrader.NinjaScript.AddOns
          {
          public partial class MySharedMethods : NinjaTrader.NinjaScript.AddOnBase
          {
          }
          }

          How is that possible?

          Thank you

          Comment


            #6
            Hello kiss987,

            That would not be possible the way you currently have it since the Addon class would have no idea what instrument you are requesting TickSize for.

            It would be possible by using BarsRequest similar to the samples on the forum post that I linked to.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              After long search, this is the solution that finally worked for me. It shares method between indicators, but not between indicators and strategies (which I don't need). Putting code in AddOns directory is for me very complex and involves passing parameters such as Highs/Lows, etc. which I do not want to do.

              https://ninjatrader.com/support/foru...74#post1051574
              Last edited by stevenev1; 03-16-2019, 09:46 AM.

              Comment


                #8
                Hello stevenev1,

                I also have an example you may find helpful.

                https://ninjatrader.com/support/forum/forum/historical-beta-archive/version-8-beta/83018-partial-class-does-not-work?p=712245#post712245
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ScottWalsh, 04-16-2024, 04:29 PM
                6 responses
                27 views
                0 likes
                Last Post ScottWalsh  
                Started by frankthearm, Today, 09:08 AM
                10 responses
                35 views
                0 likes
                Last Post frankthearm  
                Started by GwFutures1988, Today, 02:48 PM
                0 responses
                2 views
                0 likes
                Last Post GwFutures1988  
                Started by mmenigma, Today, 02:22 PM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by NRITV, Today, 01:15 PM
                2 responses
                9 views
                0 likes
                Last Post NRITV
                by NRITV
                 
                Working...
                X