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 tsantospinto, 04-12-2024, 07:04 PM
        7 responses
        126 views
        0 likes
        Last Post aligator  
        Started by futtrader, 04-21-2024, 01:50 AM
        5 responses
        56 views
        0 likes
        Last Post NinjaTrader_Eduardo  
        Started by PeakTry, Today, 10:49 AM
        0 responses
        2 views
        0 likes
        Last Post PeakTry
        by PeakTry
         
        Started by llanqui, Today, 10:32 AM
        0 responses
        5 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by StockTrader88, 03-06-2021, 08:58 AM
        45 responses
        3,994 views
        3 likes
        Last Post johntraderuser2  
        Working...
        X