Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can we use normal IO with NinjaScript ?

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

    Can we use normal IO with NinjaScript ?

    Hi - I am too new to NT to really know yet, and the question may not be very common :

    My Auto Systems heavily depend on Scaling. They do this over trades (thus not within one trade buying extra, but a new position does that after the previous fully exists).
    On the longer term this requires the ability to "Starting through" the System. This is for various reasons, like the program crashed, the PC required a reboot, etc.;

    Of course in normal C# we can do everything regarding this, but I don't readily see those normal commands (think StreamReader and the like). Is the command set shown (https://ninjatrader.com/support/help...injascript.htm) perhaps only about the NT specialties while all of C# is available ?
    And if not all is available, is there a means where I can at least read back the output of a previous Log() (the latter as a means for output) ?

    Or put differently, what would you use to permanently store some variables, and read them back later ?
    TIA !

    #2
    I personally use JSON. StreamReader is ok for parsing row by row values, for everything else JSON is preferred.
    I do not read NT logs, I have separate files for my settings and parse them. You have to write your own class that handles this.

    Comment


      #3
      When you say you don't "see" those commands, do you mean you don't see them on auto-complete or something? That seems more like you don't have your file or editor set up properly. Are you using NinjaScript Editor or Visual Studio? You can add the appropriate "using" clauses at the top of your script and use anything that's a normal part of the .NET Framework 4.8.1 including StreamReader and everything of that sort. There is full access to anything in the framework or anything else you include as a reference.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Thanks guys. All clear now.
        Bruce, I looked at the list of commands (see link I referred to). And I did not install NT or anything yet. Just contemplating whether it will do all I "desire".

        Comment


          #5
          The link you posted to the Help Guide is describing those capabilities that are UNIQUE to NinjaTrader. That's what they're adding to 5.0 C#.NET and the .NET Framework 4.8.1 all of which is available.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Just a few more helpful tidbits:

            The NinjaScript Framework is a C# library builtin to the NinjaTrader.exe
            executable, which is itself built using C# 5 and .NET Framework 4.8.1.

            This means the NinjaScript Framework is not standalone -- it is not a
            installable library with nuget -- the only way to use NinjaScript is by
            first installing NinjaTrader.

            NinjaScript is not a language, it is a builtin library that comes with
            NinjaTrader, and it's only purpose is to make NinjaTrader extensible.

            This extensibility is achieved via a well designed 'plugin' interface.
            The 3 most common plugins are Indicators, Strategies, and AddOns.

            All of C# 5 and .NET Framework 4.8.1 is available to the NinjaScript
            programmer, regardless of plugin type. In effect, the world is your
            oyster.

            -=o=-

            All NinjaScript programmers are expected to know C# and .NET. That is,
            the NT Support dept and NinjaScript docmentation do not attempt to teach
            you any of these fundamentals.

            NOTE:
            Although advanced knowledge of C# and .NET can be extremely useful,
            some parts of C#/.NET have varying degrees of usefulness in NinjaScript.
            For ex, NT8 is based on WPF, not WinForms. The NT Support dept
            frowns upon abstract base classes built on top of the plugin classes,
            and promotes the use of partial classes instead. NT8 is multi-threaded,
            and may require you to invoke a Dispatcher to run certain parts of your
            code on certain threads.

            -=o=-

            When used by NT support, the words 'supported' and 'unsupported' need
            to be kept in perspective. Many times, what they mean is 'we will not help
            you on that'. For example, are you wanting to use a Dictionary or Sockets
            in your code? Well, those things are 'unsupported', which just means that the
            Support dept will redirect you to other 3rd-party resources. This makes sense,
            their focus is strictly on NinjaScript and other platform related questions.

            But, anything documented with C# 5 and .NET Framework 4.8.1 should
            work in NinjaScript, it really depends on your own programming skills.

            My point is:
            Being told something is 'not supported' is not the same thing as 'it will not
            work'. For really advanced stuff, hearing the word 'unsupported' always
            depends on the context of the question, you own expert knowledge, and
            your specific use case.

            [As a sidenote:
            NT Support will never answer NT Brokerage related questions on these
            forums, the brokerage folks don't even read these forums. These forums
            are strictly for NinjaScript and platform related questions.]

            ​-=o=-

            So, what else gets in your way?

            NinjaTrader is using older technology, and makes little to no attempt to
            keep abreast with advances in C# and .NET releases.

            More recent versions of the C# language are not supported by NT's C#
            compiler, but you can compile w/those C# features in Visual Studio and
            use the resulting assembly.

            In NinjaTrader, you are restricted to .NET Framework 4.8.1, so the cool
            kids who have .NET Core may find NT8's plugin architecture a bit too
            ancient and restrictive.

            This can make some exciting new things, like ML.net, more difficult to
            employ -- but not impossible.

            But, yes, generally speaking, you can use C# and .NET to your heart's
            content when programming within the NinjaScript Framework.

            Welcome to NinjaScript!
            Last edited by bltdavid; 06-24-2023, 08:26 AM.

            Comment


              #7
              Originally posted by Leeroy_Jenkins View Post
              I personally use JSON. StreamReader is ok for parsing row by row values, for everything else JSON is preferred.
              I do not read NT logs, I have separate files for my settings and parse them. You have to write your own class that handles this.
              Yep, same here.

              Sooner or later, new folks discover the property grid is not always
              the best place for every setting.

              I've been known to throw bunches of extra settings into an INI file,
              then use GetPrivateProfileString to read them back.

              Why do this?
              Some settings internal to the indicator could be instantly changed
              by updating/rereading an external file (such as an INI file) whereas
              going through the property grid means reloading/rebuilding the chart.

              External file vs property grid?
              Reloading the chart can be serious baggage to endure to just change
              'one simple thing' ... remember, your chart may have a dozen other
              indicators, and if Tick Replay is enabled, that can multiply your chart
              reloading delay by a huge factor. For certain things, an external file
              of settings may be a better choice.

              Comment


                #8
                Extremely useful, David. Thank you.
                And all your comments about "support" and such are totally logical.

                Maybe a stupid question :

                But, yes, generally speaking, you can use C# and .NET to your heart's
                content when programming within the NinjaScript Framework.​
                There wouldn't be a possibility to use VB.NET, would there ?
                I ask this, because in between your lines I seem to read this possibility. E.g. :

                but you can compile w/those C# features in Visual Studio and
                use the resulting assembly.​

                Comment


                  #9
                  I suppose you can.

                  I mean, if you compile your VB.NET to an external assembly,
                  then to NT it's just like any other assembly.

                  How to combine NinjaScript with VB.NET together into the
                  same file
                  -- well, now, that is a different question.

                  I don't know. I've never done that.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  76 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  26 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  32 views
                  0 likes
                  Last Post TheRealMorford  
                  Started by Mindset, 02-28-2026, 06:16 AM
                  0 responses
                  62 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Working...
                  X