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 dpolyakov, 03-29-2024, 11:30 AM
          4 responses
          150 views
          2 likes
          Last Post NinjaTrader_RyanS  
          Started by traderqz, Today, 12:06 AM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by kujista, Today, 06:23 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          33 views
          0 likes
          Last Post Pattontje  
          Started by abdo22, Yesterday, 03:15 PM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X