Mentis course
Lesson 11. Alerts and request.security
30 min, advanced level
alertcondition(condition, title, message) declares a rule that shows in the chart's alert dialog.
alertcondition(ta.crossover(close, ta.sma(close, 50)), "Above 50", "Close crossed above the 50 SMA")
request.security(symbol, timeframe, expression) reads a value from another timeframe or symbol. Add [1] to use the last finished higher-timeframe bar, so the value never changes under your feet.
Exercises
- Daily levels. Plot the previous day's high and low on an intraday chart.
- Closed-bar alert. Fire alert() only when barstate.isconfirmed is true.
Quick quiz
Why add [1] after a higher-timeframe value?
The current higher-timeframe bar is still changing.
What does barstate.isconfirmed tell you?
It is true once the bar closed.
Education only. Not financial advice. Examples are teaching samples, not trading results.
