Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reading Name of Script?

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

    Reading Name of Script?

    How can I read the name of the actual running script, like
    actualScriptName = ...

    Thx

    #2
    BillCh,

    Don't know what you mean. The name is whatever you name it. There is no property to access it.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I have a main script, call it BillsMAINv06. I am saving versions with preset parameters not to have to change them every time, like BillsMAINv06_614_bb, BillsMAINv06_614_xh, BillsMAINv06_512_bb, BillsMAINv06_512_xh, ...

      As I want to create files with the scriptname being a part of the file name and want to write log entries (to output window etc.) referencing the particular scripts, I cannot hardcode the script name to each and every file. Also, my main script is under continous development, so my "master" script will change its name from BillsMAINv06 to BillsMAINv07 and so on. I than change the parameter presets for its variants (as above) and I do not want to have to hard code the scripts names as this would leave room for errors I wouldn't recognize immediately.

      As this is all some C# stuff and the script's name is some class or object or namespace or whatever (I am a trader, not a programmer), there sould be a way - any way - to get its name programmatically, right?

      Thx

      Comment


        #4
        This is not supported. You have to change it as you change file names.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Maybe some C#/.NET pro and non-NT-official can help me out here?

          As NT itself somehow can manage and differentiate individual scripts (like on the Strategies tab of the Control Center where one can clearly read the scripts name under the Strategy column) there must be a way to get this information.

          Thanks!

          Comment


            #6
            Bill,

            if you are looking for the class instance name of your indicator (is that what you mean by main-script?), you could try something like this (not tested):

            string fullname = this.ToString();
            string extractedName = fullname.Remove(fullname.IndexOf('('));
            Print("Extracted class instance name: " + extractedName)

            Regards
            Ralph

            Comment


              #7
              AWSOME Ralph!

              Works perfectly! Exactely what I needed, the name of the strategy!

              Thanks a lot!!

              P.S.: I don't want to overdo it, but do you also have a hint of how to get the selected account name/number? I once was told by NT staff it cannot be read. I am using IBs TWS, btw.

              Comment


                #8
                Don't know how to do that, Bill. Regards Ralph.

                Comment


                  #9
                  Again, thanks a lot for the name extraction stuff!

                  Comment


                    #10
                    Just one more comment regarding the name extraction. It is kind of static, the result doesn't change througout the entire runtime. Best location to performe the extraction therefore is the indicator's constructor. I would suggest to declare the variables as private in the standard variable section (where the wizard generated vars are located) and to execute the code in the constructor like this:

                    Code:
                    public class myInd : Indicator
                    {
                      private string fullname, extractedName;
                      ...
                      public myInd()
                      {
                        string fullname = this.ToString();
                        string extractedName = fullname.Remove(fullname.IndexOf('('));
                      }
                    }
                    Regards
                    Ralph

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    558 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    324 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    545 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    547 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X