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

local method inside OBU?

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

    local method inside OBU?

    Hi,

    I'm trying to clean up some code and pull out long sections of code inside OBU, and paste them into functions (methods) at the end of OBU. I think this is called creating local methods.

    A sample local method:
    Code:
    // Declare a local function.
             string AppendPathSeparator(string filepath)
             {
                if (! filepath.EndsWith(@"\"))
                   filepath += @"\";
    
                return filepath;   
             }
    but the compiler complains I am missing a closing curly at the line of code right before the declaration of the local function.

    Is it possible to create local methods inside OBU?

    If not, is my only choice to move it outside of OBU, and use an access modifier of private protected?

    thank you

    #2
    nope, appears i can't use private protected, just 1 modifier, protected...

    Comment


      #3
      Hello. Thanks for the note.

      You must define the method at the class level, like so:

      Code:
      protected override void OnBarUpdate()
      		{
                            ...			
      		}
      		
      		protected  string AppendPathSeparator(string filepath)
                      {
                          if (! filepath.EndsWith(@"\"))
                            filepath += @"\";
      
                          return filepath;   
                       }
      Please let us know if you have any questions.
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        I got the idea from this MSDN https://docs.microsoft.com/en-us/dot...ocal-functions


        Starting with C# 7, local functions

        So I'm assuming NT ver 8 is not using this level of c# yet.

        thanks

        Comment


          #5
          Hello.

          Thanks for the reply.

          The supported C# syntax is for .NET 3.5 and 4.5 so local functions are not supported.

          Please let us know if we may be of any further assistance.
          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Barry Milan, Yesterday, 10:35 PM
          6 responses
          18 views
          0 likes
          Last Post Barry Milan  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Started by DJ888, 04-16-2024, 06:09 PM
          4 responses
          13 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          12 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          8 views
          0 likes
          Last Post nandhumca  
          Working...
          X