Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicators based on others indicators

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

    Indicators based on others indicators

    Hello,

    I want to make EMA that is based on SMA. For example:

    Indicator1 = SMA(Close, 20)[0];

    Indicator2 = EMA(Indicator1, 5)[0];


    But it doesn't run because I can't see the Indicator2 on my screen.

    How can I create this indicator with NT8?

    Thanks in advance and regards.

    #2
    Hello soyjesus,
    Thanks for your post.

    To calculate your SMA off of your EMA simply create an SMA variable and pass that in as the input series to your EMA. Something similar to the following snippet would accomplish this.

    Code:
    private SMA MySMA;
    private EMA MyEMA;
    protected override void OnStateChange()
    {
    
    	else if (State == State.Configure)
    	{
    		AddPlot(Brushes.Orange, "MyPlot");
    	}
    	else if (State == State.DataLoaded)
    	{
    		MySMA = SMA(20);
    		MyEMA = EMA(MySMA, 5);
    	}
    }
    
    protected override void OnBarUpdate()
    {
    	Value[0] = MyEMA[0];
    }
    I am including the relevant help guide documentation used in this process, for your convenience.

    Value
    https://ninjatrader.com/support/help...-us/?value.htm

    AddPlot()
    https://ninjatrader.com/support/help...s/?addplot.htm

    Please let me know if you have any further questions.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks, but now I have another question:

      How can I put on the first parameter of SMA a double value? For example, I want to calculate the SMA(MyVariable, 20) where MyVariable is <double> and not is Close, High, etc.

      Thanks.

      Comment


        #4
        Hello soyjesus,
        Thanks for your post.

        You could create a custom series and pass that in as an input, similar to the snippet below.

        Code:
        private Series<double> MyVariable;
        private SMA MySMA;
        protected override void OnStateChange()
        {
        	else if (State == State.DataLoaded)
        		{	
        			MyVariable = new Series<double>(this,MaximumBarsLookBack.TwoHundredFiftySix);
        			MySMA = SMA(MyVariable, 20);
        		}
        }
        
        protected override void OnBarUpdate()
        {
        	if( CurrentBar < 20)
        		return;
        
        	MyVariable[0] = [COLOR="Green"]//your math here//[/COLOR];
        	Value[0] = MySMA[0];
        }
        I am including the relevant help guide documentation for this example. The Series<T> documentation shows how to create a custom series that you could pass as your input.

        Series<T>
        https://ninjatrader.com/support/help...s/?seriest.htm

        Moving Average - Simple (SMA)
        https://ninjatrader.com/support/help...simple_sma.htm

        Please let me know if you have any further questions.
        Josh G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        43 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        26 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        163 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X