Ema2 Function in NinjaScript? - NinjaTrader Programming | futures io social day trading
futures io futures trading

Ema2 Function in NinjaScript?
Updated: Views / Replies:1,992 / 3
Created: by srgtroy Attachments:2

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 100,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Thread Tools Search this Thread

Ema2 Function in NinjaScript?

  #1 (permalink)
Don't Poke The Bear!
Los Angeles, California Republic
Trading Experience: None
Platform: Sierra Chart
Broker/Data: CQG
Favorite Futures: ES
srgtroy's Avatar
Posts: 1,686 since Jan 2011
Thanks: 1,104 given, 2,769 received

Ema2 Function in NinjaScript?

In Thinkscript, there is a function called Ema2. Here is its description:

Ema2(IDataHolder data, int prefetch, double smoothing factor);


Returns the Exponential Moving Average (EMA) of data with smoothing factor. The prefetch parameter controls the number of historical data points used to initialize EMA for the first bar.


input additionalBars = 0;
plot ExpAvg = Ema2(close, additionalBars, 0.2);

The code plots the exponential average of a security Close price with a smoothing factor of 0.2. Note that studies using ema2 fetch a necessary number of additional bars for correct initialization, so adding more initialization data by increasing additionalBars input has little impact on the study.

Is there anything like this in NinjaScript?

If not, how would I go about getting the value of Ema2(Close, 5, 0.2) for instance?

Reply With Quote
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

  #3 (permalink)
Market Wizard
Berlin, Europe
Trading Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
Fat Tails's Avatar
Posts: 9,771 since Mar 2010
Thanks: 4,233 given, 26,208 received

I do not know ThinkScript, but what you describe can easily be achieved in NinjaScript.

Smoothing factor:

Usually you use an integer period to calculate an exponential moving average. If n is the integer period, this translates into a smoothing factor k = 2/(n+1). To obtain the smoothing factor 0.2, you would need to select a period of 9, as k = 2/(n+1) = 2/(9+1) = 2/10 = 0.2

Of course it is possible to change the formula of the EMA to use a smoothing factor instead of the period.


NinjaTrader uses the variable BarsRequired to cut off the unstable period during the initialization of an indicator. You can simply declare a variable prefetch, and allocate the selected value to BarsRequired.

I have modified the default EMA to catch a prefetch value and to use a smoothing constant instead of a period.

Attached Thumbnails
Ema2 Function in NinjaScript?-es-09-11-15-min-27_06_2011.jpg  
Attached Files
Register to download File Type: zip EMA2.zip (2.0 KB, 25 views)
Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
  #4 (permalink)
Don't Poke The Bear!
Los Angeles, California Republic
Trading Experience: None
Platform: Sierra Chart
Broker/Data: CQG
Favorite Futures: ES
srgtroy's Avatar
Posts: 1,686 since Jan 2011
Thanks: 1,104 given, 2,769 received

May the Force be with you, always!

Reply With Quote


futures io > > > > > Ema2 Function in NinjaScript?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

futures io is celebrating 10-years w/ over $18,000 in prizes!

Right now

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference another study that's not a function vegasfoster Sierra Chart Programming 3 June 23rd, 2011 01:41 PM
using advance search function aquarian1 Traders Hideout 5 December 26th, 2010 03:47 PM
NinjaScript equivalent of EasyLanguage's volatility function? zwentz NinjaTrader Programming 3 May 29th, 2010 01:39 AM
Losing Edit Function, looking for help! alex123 Traders Hideout 4 September 15th, 2009 07:32 PM

ai, average, code, ema, historical data, indicator, indicators, information, moving average, ninjascript, ninjatrader, thinkscript, variable

All times are GMT -4. The time now is 01:21 PM. (this page content is cached, log in for real-time version)

Copyright © 2019 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432 WhatsApp Business, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2019-06-17 in 0.19 seconds with 15 queries on phoenix