Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print EMA value of multiple instruments(tickers)

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

    Print EMA value of multiple instruments(tickers)

    Hello,
    Can someone please help me with a way (or a sample indicator) which can print the current EMA8 values for multiple instruments?
    - We can consider 1 min chart is opened (or its ok to use the chart timeframe)
    For ex: I want to know the current EMA8 values of ES 06-23, NQ 06-23, TSLA

    Sample output should be:
    EMA of ES is: .....
    EMA of NQ is: .....
    EMA of TSLA is: .....

    Many thanks in advance!

    #2
    You could do this with Market Analyzer - just add each of the symbols as a row and the EMA(8) as an indicator column.

    Click image for larger version  Name:	image.png Views:	0 Size:	7.3 KB ID:	1252730
    If it must be in NinjaScript, use AddDataSeries in OnStateChange when State == State.Configure to add each of the series, and then in OnBarUpdate, iterate through and print the EMA of each one e.g. Print("EMA of ES is " + EMA(BarsArray[1],8)[0].ToString()); Be sure to check to make sure that enough bars are present on each series.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hi Bruce,
      First of all, many thanks for helping me here. I do not want to use the Market Analyzer as it doesn't suite my use-case (I want to have it as an indicator).
      Below is the indicator that I have written and somehow it is printing the EMA8 values of only 1st ticker and repeating the same value for all the remaining tickers.

      Can you please help me here?

      region Using declarations

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;

      #endregion

      namespace NinjaTrader.NinjaScript.Indicators.MY
      {
      public class EMA8Values : Indicator
      {
      // Define class-level variables for MACD indicators
      private Dictionary<string, EMA> ema8Values;
      private List<string> tickerSymbols = new List<string>() { "TSLA", "NFLX", "MES 06-23", "MNQ 06-23" };

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "EMA8Values";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      DisplayInDataBox = true;
      DrawOnPricePanel = true;
      DrawHorizontalGridLines = true;
      DrawVerticalGridLines = true;
      PaintPriceMarkers = true;
      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      IsSuspendedWhileInactive = true;
      }
      else if (State == State.Configure)
      {
      ema8Values = new Dictionary<string, EMA>();

      foreach (string tickerSymbol in tickerSymbols)
      {
      ema8Values[Instrument.FullName] = EMA(Close, 8);
      }
      }
      }

      protected override void OnBarUpdate()
      {
      if (CurrentBars[0] < 100)
      return;

      ema8Values = new Dictionary<string, EMA>();

      foreach (string tickerSymbol in tickerSymbols)
      {
      ema8Values[Instrument.FullName] = EMA(Close, 8);
      }


      // Loop through the ticker symbols and fetch MACD values
      foreach (string tickerSymbol in tickerSymbols)
      {
      EMA ema8 = ema8Values[Instrument.FullName];

      double ema8V = ema8[0];

      Print("EMA8 for " + tickerSymbol + ": " + ema8.ToString());
      }
      }
      }
      }

      Comment


        #4
        Hello sriniadupa,

        Thanks for your post.

        As QuantKey_Bruce stated, if you want to create a custom NinjaScript that prints out the EMA(8) value of multiple instruments, you must add each data series you want to use to your script calling the AddDataSeries() method in OnStateChange() when the State == State.Configure.

        Then, you could supply the BarsArray of the added series to the EMA() to have that EMA calculate using the added series. For example:

        //OnBarUpdate()
        Print("EMA of ES is " + EMA(BarsArray[1],8)[0]);
        Print("EMA of NQ is " + EMA(BarsArray[2],8)[0]);


        See the help guide documentation below for more information and sample code.

        AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
        EMA(): https://ninjatrader.com/support/help...onential_e.htm
        BarsArray: https://ninjatrader.com/support/help.../barsarray.htm
        See the 'Using Bars Objects for Inputs to Indicator Methods' section of this help guide page: https://ninjatrader.com/support/help...nstruments.htm
        Make Sure You Have Enough Bars in the Data Series You Are Accessing: https://ninjatrader.com/support/help...nough_bars.htm
        Last edited by NinjaTrader_BrandonH; 05-24-2023, 08:00 AM.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        606 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        353 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X