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 sightcareclickhere, Today, 01:55 PM
        0 responses
        1 view
        0 likes
        Last Post sightcareclickhere  
        Started by Mindset, 05-06-2023, 09:03 PM
        9 responses
        258 views
        0 likes
        Last Post ender_wiggum  
        Started by Mizzouman1, Today, 07:35 AM
        4 responses
        18 views
        0 likes
        Last Post Mizzouman1  
        Started by philmg, Today, 01:17 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by cre8able, Today, 01:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X