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

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 devatechnologies, 04-14-2024, 02:58 PM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by tkaboris, Today, 08:01 AM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by BarzTrading, Today, 07:25 AM
        1 response
        11 views
        1 like
        Last Post NinjaTrader_Clayton  
        Started by EB Worx, 04-04-2023, 02:34 AM
        7 responses
        161 views
        0 likes
        Last Post VFI26
        by VFI26
         
        Started by Mizzouman1, Today, 07:35 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X