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 4,186 views
    2. thumb_up 5 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #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?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
The May 31 Binary: 60% Trump Declares Iran Ops Over, Onl …
Prediction Markets & Event Contracts
February NFP Preview -- Why This Mornings Jobs Number Co …
Traders Hideout
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
  #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
Thanked by:
  #4 (permalink)
Richard
Dallas TX/USA
 
Posts: 153 since Jun 2009
Thanks Given: 33
Thanks Received: 285


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
Thanked by:
  #5 (permalink)
 
roonius's Avatar
 roonius   is a Vendor
 
Posts: 131 since Jun 2009
Thanks Given: 20
Thanks Received: 298


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


© 2026 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 - Downloads - Top
no new posts