Benny Rodríguez
Benny Rodríguez

Reputation: 47

Get data of EMA for a certain bar

I have a little trouble using Pinescript from TradingView. I need to compare the lowest price in a bar to the value of an EMA at the same price bar. I mean, if I have drawn an EMA for 20 diary price bars, how can I obtain the value of this EMA for certain day. For example, what is the value of this EMA in day 12?

Would you help me, please? Thank you in advance

Upvotes: 0

Views: 1095

Answers (1)

bbnm
bbnm

Reputation: 1094

You can use the history referencing operator [].

EMA200 = ta.ema(close, 200)
EMA200TwelveBarsAgo = EMA200[12]

You can also use the ta.valuewhen(condition, source, occurence) function with date and time conditions.

var twoHoursAgo = timenow - 1200000
EMA200TwoHoursAgo = ta.valuewhen(twoHoursAgo, EMA200, 0)

*Pinescript version=5

Upvotes: 1

Related Questions