NexusFi: Find Your Edge


Home Menu

 





Ema2 Function in NinjaScript?


Discussion in NinjaTrader

Updated
    1. trending_up 4,157 views
    2. thumb_up 2 thanks given
    3. group 1 followers
    1. forum 3 posts
    2. attach_file 2 attachments




 
Search this Thread

Ema2 Function in NinjaScript?

  #1 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722

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

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

Description

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.

Example

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?

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
Futures True Range Report
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
GFIs1 1 DAX trade per day journal
22 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
The Program
20 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


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.

Prefetch:

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
Click image for larger version

Name:	ES 09-11 (15 Min)  27_06_2011.jpg
Views:	129
Size:	87.2 KB
ID:	42168  
Attached Files
Elite Membership required to download: EMA2.zip
Reply With Quote
Thanked by:
  #4 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722

May the Force be with you, always!

Started this thread Reply With Quote




Last Updated on June 29, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts