Exponential Moving Average¶
Exponential moving average indicator to add on a estrade.CandleSet
object.
Parameters
Name | Type | Description | Default |
---|---|---|---|
periods |
int |
nb of periods | required |
name |
str |
name of indicator | required |
Warning
It is strongly advised to give a name to your indicator so you can fetch
their values in your strategy (see estrade.Strategy.get_indicator
)
Example
from estrade import Epic, CandleSet, ExponentialMovingAverage, Strategy
class MyStrategy(Strategy):
def on_new_candle_opening_strategy(candle_set):
# fetch indicator value
ema200 = candle_set.indicator(indicator_name='ema200')
# check if indicator value is defined (for the first 199 ticks,
# the Moving Average 200 will not be set)
if ema200.value:
# do something....
def on_new_tick_opening_strategy(tick):
# to fetch indicator, the from a `on_new_tick...` method in strategy,
# the easiest way is to use the `Strategy.get_indicator()` helper
ema200 = self.get_indicator(timeframe='5minutes', name='ema200')
# check if indicator value is defined (for the first 199 ticks,
# the Moving Average 200 will not be set)
if ema200.value:
# do something....
ema200 = ExponentialMovingAverage(periods=200, name='ema200')
cs_5mn = CandleSet(timeframe='5minutes', indicators=[ema200])
epic = Epic(candle_sets=[cs_5mn])
#...