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 DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Working...
        X