SmartQuant Discussion
http://www.smartquant.com/forums/

How to compare ema with ema previous bar
http://www.smartquant.com/forums/viewtopic.php?f=64&t=6458
Page 1 of 1

Author:  maxpi [ Thu Feb 07, 2008 4:00 am ]
Post subject:  How to compare ema with ema previous bar

What code would I use to compare the EMA of the current bar with EMA of the previous bar?

EMA ema1;
ema1[0].CompareTo(ema1[1])>0 ??
ema1[0] >ema1[1] ??
ema1.Ago(0).CompareTo(ema1.Ago(1))>0 ??

Author:  Dr. Anton Fokin [ Thu Feb 07, 2008 2:00 pm ]
Post subject: 

ema[ema.Count-1] is the last (most current) entry in the ema indicator series (which is a time series of double number)

Correspondingly

ema[ema.Count-2] is the previous entry.

All together

Code:
if (ema[ema.Count-1] > ema[ema.Count-2])
  do something

If you want to write it more elegantly, you can use Indicator.Last and Indicator.Ago

Code:
if (ema.Last > ema.Ago(1))
  do something

also, you can simply use Ago everywhere since Indicator.Ago(0) is the same as Indicator.Last

Code:
if (ema.Ago(0) > ema.Ago(1))
  do something

Regard,
Anton

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/