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 rocketman7, Today, 02:12 AM
          6 responses
          28 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by guillembm, Yesterday, 11:25 AM
          3 responses
          16 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by junkone, 04-21-2024, 07:17 AM
          10 responses
          148 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by tsantospinto, 04-12-2024, 07:04 PM
          6 responses
          101 views
          0 likes
          Last Post tsantospinto  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          7 responses
          28 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X