NexusFi: Find Your Edge


Home Menu

 





Get the EMA of a double value???


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one roonius with 1 posts (0 thanks)
    2. looks_two eDanny with 1 posts (2 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Richard with 1 posts (3 thanks)
    1. trending_up 3,631 views
    2. thumb_up 5 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Get the EMA of a double value???

  #1 (permalink)
 Curbfeeler 
Central Iowa
 
Experience: Beginner
Platform: NinjaTrader
Posts: 22 since Nov 2009
Thanks Given: 34
Thanks Received: 16

A guy named Prospectus put out a free indicator for ThinkorSwim.

https://readtheprospectus.wordpress.com/2009/01/30/volatility-based-trailing-stop/

He designed it as a trailing stop, but I've found that it's very close to Step MA and that it might be helpful as a trend indicator.

Long story short, I'd like to backtest this indicator against my /ES tick data and see how it does. I want to recreate the indicator in NinjaTrader.

The logic is pretty simple.

# Calculate average range for volatility:
#
def atr = expaverage(high-low,length);
#
# Calculate initial short and long volatility stop values:
#
def svs =low+ceil(mult*atr/ticksize())*ticksize();
def lvs =high-ceil(mult*atr/ticksize())*ticksize();

To complete the first part, I basically need the EMA of the (high - low) price.

So what's the best way to calc the EMA for something that's not a price or a dataset? In this case the difference is just a floating point number. Should I set that into a new dataset? Should I use an array?

Any help is appreciated. Thanks in advance.

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Funded Trader platforms
Traders Hideout
Request for MACD with option to use different MAs for fa …
NinjaTrader
Ninja Trader 8 Drawing Tools Wanted
NinjaTrader
 

  #3 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425


Create a Data Series and then do the calc for each bar in the Data Series.

HighLowSeries.Set(High[0] - Low[0]);

EMA(HighLowSeries, length)[0];

Reply With Quote
The following 2 users say Thank You to eDanny for this post:
  #4 (permalink)
Richard
Dallas TX/USA
 
Posts: 153 since Jun 2009
Thanks Given: 33
Thanks Received: 284


Curbfeeler View Post
So what's the best way to calc the EMA for something that's not a price or a dataset? In this case the difference is just a floating point number. Should I set that into a new dataset? Should I use an array?

Since it's just an ema, you can do this (for an object variable 'double ema'):

 
Code
 ema = ema + (2.0/(len+1.0))*( (High[0]-Low[0]) - ema );
... but if you want to use ninja's built-in EMA indicator, then define a dataseries 'highlow', and initialize it in Initialize():
 
Code
highlow = new DataSeries(this);
... and use it like so:
 
Code
highlow.Set(High[0] - Low[0]);
ema = EMA(highlow, len)[0];

Reply With Quote
The following 3 users say Thank You to Richard for this post:
  #5 (permalink)
 
roonius's Avatar
 roonius   is a Vendor
 
Posts: 131 since Jun 2009
Thanks Given: 20
Thanks Received: 295


eDanny View Post
Create a Data Series and then do the calc for each bar in the Data Series.

HighLowSeries.Set(High[0] - Low[0]);

EMA(HighLowSeries, length)[0];


NinjaTrader has already everything built-in:

EMA(Range(), length)[0];

Reply With Quote





Last Updated on April 9, 2010


© 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