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

How to structure NinjaScript Indicator program?

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

    How to structure NinjaScript Indicator program?

    I wrote a system in Visual Studio Express and I am planning to turn it into an Indicator in NinjaScript. The system is fairly big; I currently have 65 files. I don't expect to use all of them, but it is still going to be a fairly big indicator.

    How do you recommend to structure the program? Is there any documentation about it?
    I would like to be able to keep the structure once version 8 is available and I can develop in Visual Studio.

    Thank you

    #2
    Hello,

    Thank you for the question.

    I would like to ask, you said you have created the item outside of NInjaTrader, is this just a general C# program you have developed or is this made for NinjaTrader currently using NinjaScript?

    If this is not already built using NinjaScript methods/logic/structure you will likely need to re create the item to be in specification with how the platform works.

    In general it is not recommended to start items outside of NinjaTrader, specifically with Indicators as these have to be compiled in the platform to be valid. There is extra code appended at the bottom of an indicator that is not generated unless you use the NinjaScript editor and compile from NinjaTrader.

    Based on the information given, you will likely need to re create the files to be valid NinjaScript and will likely need to debug and test before this would work as it does now.

    Once you have the correct NinjaTrader structure of files and it compiles and works correctly in NinjaTrader 7, you can use that as reference once 8 is released to do any conversions needed for 8.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Jesse,

      Thank you for your prompt answer.

      The program I have now is written in a regular c# and it does not have anything to do with NinjaTrader.

      I understand, that I have to create my indicator in NinjaTrader and then add my code to it.

      My question is how I should organize my code.
      Where I should put my classes, should it be a separate folder, how to refer to it, etc.

      I am sorry for asking such basic questions; the answers should, probably, be somewhere in documentation, but I did not find them.

      So far I've just ported a couple of indicators into NinjaTrader and my experience is very limited.

      Thank you

      Comment


        #4
        Hello,

        Thank you for the reply.

        The structure would depend on what your code needs to do and what structure it already has.

        Regarding NinjaTrader, the type of file (Indicator or Strategy) would determine part of how you need to structure your code as well. For graphic items or calculations, generally indicators are best for this, strategies can then call on indicators to provide signals for trading. This is the general structure or link you would follow when creating items.

        All files are compiled when you compile, so you can use standard C# code for namespaces, classes etc. in separate files, you can create an indicator and just delete the code out of the file to create your own script. There is a sample of a simple class, this could go in one file, or two it would be up to you: http://ninjatrader.com/support/forum...33&postcount=6

        I wouldn't be able to really say how you need to structure your file as I do not know all of the logic used, instead you would need to migrate piece by piece into NinjaTrader and test to ensure everything is logically working. It would likely be best to create a few strategies that call on indicators to see how the underlying logic works in the platform. You could then move to porting the core logic or structure needed by your current application.

        NinjaTrader also has excellent debugging capabilities so while you are creating the scripts you can print output if needed to verify results, there is more on this subject here:

        We also have a lot of content you can learn from on the forum at the following links:




        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          Thank you for your prompt reply. I should apologize, I obviously did not formulate my question well. I will try to formulate it more precisely in order for you to be able to better understand both of what I am trying to achieve and my difficulties.

          I want to create an indicator in NinjaScript. Actually it is not exactly an indicator, as they are used regularly. It would just show buy and sell signals. This is something like ShowMe in Tradestation.

          I am going to have several such indicators, as they are customized for each market. The files that generate signals are already written in c#. I currently have 65 files per indicator.

          My question is how to add them to a single indicator file, generated by NinjaScript.

          I obviously cannot put all the code inside the indicator file.

          I read in documentation that I can create an indicator file, erase everything in it and add my code, but with amount of files I have I would pollute indicator area and will never be able to find anything. Also, I may have some files with the same names, but somewhat different content as I add indicators for different markets. Additionally I have an .xml file with all the parameters and I am not sure where to put it.

          Ideally, I would like to have my files in some separate area and only call one main function from an indicator.

          I see an option of making a DLL out of it outside of NinjaTrader. It is not the ideal solution either as I would not be able to use any of NinjaScript classes.

          What is the best way to do it?

          Thank you very much

          Comment


            #6
            Hello,

            NinjaScript/C# is all compiled together so standard C# practices would apply, this is still just C#. If you have multiple classes or files that all relate to one indicator, they can all go in a single script or be put in many files, that is up to you. You would still use the classes and other code you have just as you normally would in a C# application in the sense of Namespaces and structure and how you call on your own code. The separation of files/classes/etc would be identical to a standard C# application you may design.

            You would put the extra files in the Indicator folder generally, these will not show up In NinjaTrader unless they are indicators. You can see them in the edit NinjaScript menu to edit these scripts so they will not pollute the platform in anyway. Only items that Inherit from specific interfaces would be actual indicators or strategies or other type of NinjaScript file.

            After you have developed the item and determine it works correctly, you could then export the files as a compiled DLL from the platform that is either protected or not. After doing this you can remove the source code and store that somewhere secure, and import the dll to "clean" the folder up.

            In general because you have the compiler and code editor built into the platform, you can test any coding situation you may need yourself to see if it would work or not. I would suggest first getting comfortable with the environment you are using regarding how the compiler works, how your custom classes or files are compiled, structure of your general C# code and usages, and finally NinjaScript specific code.

            Because you have many files, I would recommend just taking the base structure for a few files and create them inside the platform, it will tell you if there are syntax errors or other problems, otherwise if it compiles and you can call on your custom code you have the correct syntax and can continue.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            3 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X