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

Writing scripts that are indicators or strategies -- how?

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

    Writing scripts that are indicators or strategies -- how?

    I am new to coding with NinjaScript and have an organizational/architectural question.

    So far, I get the sense that I can either write an Indicator or a Strategy and that my code must run from within one of these situations. To use the correct terminology, my script is "hosted" via an indicator or a strategy, and its context is the chart and ticker to which it is attached. Did I get this right?

    The larger question for me is: can I write other types of scripts besides these?

    I'd like to write a scanner that isn't attached to any particular indicator, strategy or window, but that simply runs in the background checking various instruments and notifying me of various moves on the Market Analyzer window.

    Can I do this in a way that does not require me to create it as an indicator or a strategy or run it from within one of these?

    I did not find any place in the doc that suggested the best practice for this, but it is quite possible I missed such a discussion. Do you have a link to doc that tackles this question?

    Thank you in advance for any help you can provide. Cheers.

    #2
    Hello carnitron,

    Welcome to the NinjaTrader forums!

    Below is a link to a forum post with helpful resources on getting started with NinjaScript and C#. Be sure to watch the training videos 'Automate Your Trading with NinjaTrader's Strategy Builder' and 'NinjaScript Editor 401'.


    Indicators are used to make calculations and render plots and drawing objects or provide other tools.
    Strategies are used to automate submitting entry and exit orders based on coded logic.
    Strategies can host indicators, Indicators can call and host other indicators, however an indicator cannot call / host a strategy.

    The data processed as the primary series will be from the Data Series selected as the Input Series for the script. This could be from the Data Series window from a chart or from the strategy parameters when adding a strategy directly to the Strategies tab of the Control Center.

    You can also add series with AddDataSeries.


    Typically "scanners" are added as indicator columns to the Market Analyzer with rows of instruments.



    You can also make a custom addon that does bars request that would not be added to a chart.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3

      Hi Chelsea. Thanks for such a prompt response and thank you for all the resources!

      It sounds like I want to make an addon.

      I could do my scanner as indicator or a strategy, but ultimately I'm having a hard time getting past why it should have a primary series. It shouldn't really prefer one ticker or over another, and it seems conceptually incongruous to have to attach it to a particular chart. Though I get the sense I could still make it work in either situation if I had to, even if it would feel a little weird.

      I definitely plan to add a custom column to my scanner so it can use that to sort the best tickers to the top.

      So just to be clear, can you confirm that a single addon could do all of the following simultaneously:

      1. Subscribe to an arbitrary # of data series.
      2. Trade an arbitrary number of instruments.
      3. Update the Market Analyzer window.

      If so, I think that feels the cleanest conceptually. Plus, it sounds like I'd have the ability to add other functionality over time, such as additional windows, user input, persistence, etc.

      One last question for now: What does "hosting" mean exactly? Is there a precise/technical description of it somewhere?

      Comment


        #4
        Hello carnitron,

        When adding an indicator column, the MarketAnalyzer would instantiate an instance of the indicator for each instrument row separately.

        A chart would load a specific instrument, which is the primary series. The indicator can additional instruments behind the scenes with AddDataSeries().

        A script needs data to run. The primary series is the data it processes. If you want to run on multiple instruments in rows use the MarketAnalyzer. If you want a single chart but the script to load additional data, use AddDataSeries().

        A host is the caller script. It's the one that instantiates the class and holds it in a variable until its ready to release it. The called indicator is hosted, in that it's parent that is calling it is where it reports back to.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea. My questions at this point are not about how it works, but which is the cleanest approach. (While I'm new to NinjaTrader, I'm a software engineer by trade, so I worry about things like best practices.) It's super cool that I can load and listen to an arbitrary number of data series, and it sounds like that works from anywhere. I'm trying to avoid having a primary series in the context of this scanner, simply b/c the concept doesn't make sense, given what the scanner seeks to do (treat all instruments in an an arbitrary bag of instruments equally).

          Since I can load and listen to multiple series regardless, not having a primary series seems like it is no big loss.

          As for hosting. What defines "script" in your definition? Is that a NinjaTrader dev slang term for a C# class that derives off of Indicator, Strategy or AddOnBase? Or do you mean it is the C# object implementing the NinjaTrader context from which my C# class is called from?

          So if I have written a CustomAddOn and a CustomIndicator and my CustomAddOn has a variable to a CustomIndicator instance, is that all that is necessary to have "hosting" relationship? Do my CustomAddOn and CustomIndicator know they are in a hosting relationship at this point? Is there additional functionality they can access via this relationship? Or do I just have a variable to my indicator (lol) and we are merely using the term hosting to mean that here? (i.e. it is no more than a standard C# reference and a conventional containment relationship.)

          The other situation would be like when a MarketAnalyzer has a custom indicator column and a CustomIndicator for each row. In that case, would it be correct to say that the MarketAnalyzer is hosting multiple instances of the CustomIndicator?

          Comment


            #6
            Hello carnitron,

            A script would be a class that runs in NinjaTrader that is not a full program. An indicator, strategy, addon, bar type, chart style, optimizer, market analyzer column, and superdomcolumn would all be scripts.


            It sounds like you just want a normal indicator (that doesn't add additional series) added to the Market Analyzer as a column and used as a scanner. You can filter and set alerts for multiple instruments.

            An addon, unfortunately, cannot call (host) an indicator. Indicators can only be called from strategies and other indicators, but can be added to the Market Analyzer, Chart, and SuperDom.

            Calling an indicator from a script makes the calling script a host script and the called indicator a hosted indicator.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Today, 06:40 PM
            0 responses
            10 views
            0 likes
            Last Post algospoke  
            Started by maybeimnotrader, Today, 05:46 PM
            0 responses
            7 views
            0 likes
            Last Post maybeimnotrader  
            Started by quantismo, Today, 05:13 PM
            0 responses
            7 views
            0 likes
            Last Post quantismo  
            Started by AttiM, 02-14-2024, 05:20 PM
            8 responses
            168 views
            0 likes
            Last Post jeronymite  
            Started by cre8able, Today, 04:22 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X