Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Placement of user Method code?

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

    Placement of user Method code?

    If I create a method, where within an indicator or strategy should I place the code?

    Brooks

    #2
    In the UserDefinedMethods.cs file that can be accessed from Control Center>tools>edit Ninja script and select either Indicator or strategy. The file is accessable in either one.

    Comment


      #3
      So the code would be placed right after:

      partial class Indicator
      {
      }

      ?

      Thanks, Dan.

      Comment


        #4
        No, I don't think that was right. I need to place it outside the namespace definition like this, right?

        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        /// This file holds all user defined indicator methods.
        /// </summary>
        partial class Indicator
        {
        }
        }
        // This method prints out the data and time
        private void PrintDateTime()
        {
        Print(DateTime.Now.ToString());
        }

        Comment


          #5
          Originally posted by brooksrimes View Post
          So the code would be placed right after:

          partial class Indicator
          {
          Put code here as in
          publicvoid example(int TradeStart, int TradeEnd, refbool StartArrow, refbool EndArrow)
          {
          }
          }

          ?

          Thanks, Dan.

          See where the functions/methods go?

          Comment


            #6
            there are 2 partial classes that are 2 separate files, one for indicators and another for strategies

            Comment


              #7
              If you want to create a new method inside your indicator, be sure to place outside of another method, for example not in your OnBarUpdate(), see the attached little example of calculating your custom MA value inside a custom method.
              Attached Files

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              630 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              364 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              566 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              568 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X