Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using custom indicator in strategy

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

    Using custom indicator in strategy

    Hello,

    I tried using

    Code:
    if (State == State.DataLoaded)
    {
         AddChartIndicator(HeikenAshi8);
    }
    So that I could hopefully refer to the open and close price of the current and previous bar as calculated by the indicator within a strategy, but no dice.

    I was told there's an issue with the NT built-in Heiken Ashi bars and to use the HeikenAshi8 indicator. That's what I'm up to but I've never added a custom indicator to a strategy before.

    I tried searching around and tried using the above code but came up short and figured I'd post this question: how do I refer to the OHLC data from this custom indicator within a strategy?

    #2
    Hello WalterSkinner,

    Thanks for your post.

    AddChartIndicator() is only for the purpose of adding the indicator to the chart. It does not make the indicator's data available to the strategy.

    To use an indicator's data in a strategy you have to (following recommended practices) create a private instance of the indicator, initialize the indicator, and then access as needed in the OnBarUpdate() section.

    In the case of HiekenAshi8 indicator, in your strategy:
    At the class level you would add: private HeikenAshi8 myHA; // myHA is only a name your strategy will use so feel free to call it anything
    In State.DataLoaded you would add: myHA = HeikenAshi8(); // no parameters needed for this indicator
    In State.DataLoaded you would add: AddChartIndicator (myHA); // adds indicator as a convenience when the strategy is applied and enabled.

    In the OnBarUpdate() you would access the needed values like myHA.HAClose[0]

    For your convienience/understanding I have created an example strategy that does the above and will output the HA values to the New>Ninjascript output window when the strategy is applied to a live chart.

    HeikenAshiIndicatorStrategyExample.zip

    Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

    Note — To import NinjaScripts you will need the original .zip file.

    To Import:
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.
    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello WalterSkinner,

      Thanks for your post.

      AddChartIndicator() is only for the purpose of adding the indicator to the chart. It does not make the indicator's data available to the strategy.

      To use an indicator's data in a strategy you have to (following recommended practices) create a private instance of the indicator, initialize the indicator, and then access as needed in the OnBarUpdate() section.

      In the case of HiekenAshi8 indicator, in your strategy:
      At the class level you would add: private HeikenAshi8 myHA; // myHA is only a name your strategy will use so feel free to call it anything
      In State.DataLoaded you would add: myHA = HeikenAshi8(); // no parameters needed for this indicator
      In State.DataLoaded you would add: AddChartIndicator (myHA); // adds indicator as a convenience when the strategy is applied and enabled.

      In the OnBarUpdate() you would access the needed values like myHA.HAClose[0]

      For your convienience/understanding I have created an example strategy that does the above and will output the HA values to the New>Ninjascript output window when the strategy is applied to a live chart.

      [ATTACH]n1183637[/ATTACH]

      Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

      Note — To import NinjaScripts you will need the original .zip file.

      To Import:
      1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
      2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
      3. Select the downloaded .zip file
      4. NinjaTrader will then confirm if the import has been successful.
      Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
      I don't understand how it's possible that you guys are so awesome.

      It's like every time I ask a question you guys just go so far above and beyond expectations.

      Thank you so much!

      Comment


        #4
        I have a similar question and have looked in many places, but have now found the thing I'm looking for. I want to create an automated strategy in strategy builder that buys and sells on buy/sell signals from a 3rd party indicator called T3Pro from Ninza.co. It generates this signal description. Dedicated NinjaScript signals:
        • Signal_Trend: 1 = uptrend, -1 = downtrend
        ​How do I access this signal and make a very simple buy/sell strategy I can backtest? Thank you!

        Comment


          #5
          Originally posted by vinnieray View Post
          I have a similar question and have looked in many places, but have now found the thing I'm looking for. I want to create an automated strategy in strategy builder that buys and sells on buy/sell signals from a 3rd party indicator called T3Pro from Ninza.co. It generates this signal description. Dedicated NinjaScript signals:
          • Signal_Trend: 1 = uptrend, -1 = downtrend
          ​How do I access this signal and make a very simple buy/sell strategy I can backtest? Thank you!
          vinnieray - Assuming the 3rd party indicator is usable in Strategy Builder (not all of them are!) in which case you can access it via the "Indicator" folder and select it​. Feel free to look up the NT8 online help ...

          Comment


            #6
            Hello vinnieray,

            Thanks for your notes.

            The Strategy Builder is only able to access indicators that add a plot to the indicator using the AddPlot() method. If the indicator does not contain the AddPlot() method to add a plot to the indicator then it would not be accessible in the Strategy Builder.

            As WattMan noted, if the indicator is accessible in the Strategy Builder then you could find the indicator located in the Indicators folder when creating condition and actions in the Strategy Builder.

            The best way to begin learning NinjaScript is to use the Strategy Builder. With the Strategy Builder, you can set up conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

            Strategy Builder Conditions: https://ninjatrader.com/support/help...on_builder.htm
            Strategy Builder Actions: https://ninjatrader.com/support/help...t8/actions.htm

            Below is a link to a forum post with helpful information about getting started with NinjaScript.
            https://ninjatrader.com/support/foru...040#post786040

            I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript:
            https://ninjatrader.com/support/help..._resources.htm

            If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:
            https://ninjatrader.com/support/help...g_concepts.htm

            And the MSDN (Microsft Developers Network) C# Language Reference.
            https://ninjatrader.com/support/help...erence_wip.htm​​
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Thank you guys for the quick info links. I'll dig into them to see how to get this strategy made. The 3rd party indicator says it is useable in Market Analyser and Strategy Builder, so I'm optismistic.

              Comment


                #8

                Hello, i read how the previous issues where solved and understood part of my problem on how to add a 3rd party indicator to ninjascript code strategy, but im having a really hard time identifying how to call this indicator ( Fair Value Gap (ICT) v0.0.3.0) which i downloaded from the ecosystem. As i dont know how its named to create a private instance calling this specific indicator, i will attatch the indicator below, any help is welcome!

                Also please let me know why indicator isnt accesible through nt8 strategy builder and how could this be fixed or if it is even programmable on a ninjascript strategy.

                Thanks!​
                Attached Files

                Comment


                  #9
                  Hello joanvanbeek9,

                  For an indicator to appear in the Strategy Builder it has to add plots with AddPlot() and return the Values[plot index] in the getter of a public Series<double>.
                  Below is a link to a support article that outlines what is necessary.


                  This indicator does not appear to be designed for being hosted by a strategy or another indicator and does not add any plots.
                  Instead it appears to draw text and rectangles on the chart, which cannot be accessed from the Strategy Builder.

                  If you are wanting to modify a custom copy of the script with custom logic to set plot values, this example below demonstrates setting a plot value when a condition is true.
                  Possibly you could set a plot value when the rectangle is drawn.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  54 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  130 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  73 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  49 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X