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

Best Practices

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

    Best Practices

    Hi,

    If I have code that I am going to use repeatedly in different indicators/strategies in the form of a method but want to be able to export with an indicator/strategy, what is the best way to handle this?

    If I didn't need to be able to export the code I would just use UserDefinedMethods. Any advice/comments will be appreciated.

    Best Regards,
    Scott

    #2
    Hi Scott,

    If you intend to export, then adding the method to your own indicator script is the best way to go. The method should be written as below to have a large enough scope that other indicators can access. Depending on your design, you may want to have one dedicated script for creating your own methods or a separate script for each method.


    public class myMethods : Indicator
    {
    public void PrintDateTime()
    {
    Print(DateTime.Now.ToString());
    }
    }

    You can then access this method by calling myMethods().PrintDateTime();
    Last edited by NinjaTrader_RyanM1; 04-12-2011, 05:09 PM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan, that is somewhat the conclusion I came to but for clarification I have a follow up question.

      Are you basically saying have an indicator that contains methods but doesn't really do anything or are you saying put that code in every indicator (and by extension strategy) that uses it?

      If I put the method(s) in an indicator do I need to add the indicator to the indicator or can I make the method(s) public and call them from anywhere?

      Best Regards,
      Scott

      Comment


        #4
        Good catch - should be public instead of private.

        Yes, have one indicator that only handles your custom methods. You only need to add each method once and do not need to add this indicator separately to another script.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Perfect. Thanks so much, as always, you guys are great.

          Best Regards,
          Scott

          Comment


            #6
            Ryan,

            The code example is welcomed, but as a newbie to NinjaScript what placement of that code is recommended.
            Last edited by genesis19594; 04-15-2011, 11:13 AM.

            Comment


              #7
              Hi genesis19594,

              Welcome to the NinjaTrader forums!

              If you're new to NinjaScript, I would start with the tutorials available here.

              It's good to be familiar with the structure of indicator and strategy scripts before worrying about coding your own custom methods. Once you've gone through the tutorials, check out this page for general help creating custom methods.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              12 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by terofs, Today, 04:18 PM
              0 responses
              8 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by nandhumca, Today, 03:41 PM
              0 responses
              6 views
              0 likes
              Last Post nandhumca  
              Started by The_Sec, Today, 03:37 PM
              0 responses
              3 views
              0 likes
              Last Post The_Sec
              by The_Sec
               
              Started by GwFutures1988, Today, 02:48 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Working...
              X