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

AddChartIndicator doesnt work for me

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

    AddChartIndicator doesnt work for me

    I am trying to write an indicator that calls and displays several other indicators on NT8. For test I am trying to show a 20 period SMA and 30 period SMA called from my test indicator. Based on the documentation I tried the following but get an error:

    else if (State == State.DataLoaded)
    {

    AddChartIndicator(SMA(20));
    AddChartIndicator(SMA(30));

    }

    AddChartIndicator does not exist in the current context.

    code breaking section and addchartindicator help seem to have different info which I couldn't get either to work. How do I do this?

    #2
    Hello afshinmoshrefi,

    Thanks for opening the thread.

    Indicators can only plot to the main chart panel or the panel added by the indicator. This is set with the IsOverlay property.

    AddChartIndicator() is available through the context of a strategy and is not available from an indicator. From an indicator, you can have multiple indicators added and have their calculations feed additional plots in the main indicator, but you cannot have an indicator plot to multiple panels.

    You could create an empty strategy that adds these indicators to other panels with AddChartIndicator(), or you can save a chart template to speed up chart creation.

    I've included documentation links on AddChartIndicator() and Chart Templates.

    AddChartIndicator() - https://ninjatrader.com/support/help...tindicator.htm

    Chart Templates - https://ninjatrader.com/support/help...AChartTemplate

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      How to get values for 2 indicators inside another

      I'll ask the question differently.

      Inside a Test indicator, how can I get values for SMA(20) and SMA(30) for computation purposes? this was easily done on NT7.

      Comment


        #4
        Hello afshinmoshrefi,

        This would be done as follows:

        Code:
        double value = SMA(20)[0];
        Print("The current SMA value is " + value.ToString());
        Code:
        double value2 = SMA(30)[0];
        Print("The current SMA value is " + value.ToString());
        You can also add an instance of an indicator to the main indicator and assign the indicator to the instance in OnStateChange() State.DataLoaded.

        For example from SampleMACrossover:
        Code:
        private SMA smaFast;
        private SMA smaSlow;
        
        protected override void OnStateChange()
        {
        	if (State == State.SetDefaults)
        	{
        		
        	}
        	else if (State == State.DataLoaded)
        	{
        		smaFast = SMA(Fast);
        		smaSlow = SMA(Slow);
        I'll include links to documentation on System Indicator methods and reference to the SMA so you can reference syntax for other indicators.

        SMA - https://ninjatrader.com/support/help...simple_sma.htm

        Valid Input for Indicator Methods - https://ninjatrader.com/support/help..._indicator.htm

        Please let me know if I can be of additional help.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,607 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        15 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X