About
Many traders watch the previous day's high and low, or last week's, as levels where price tends to react. This indicator gives a strategy those levels on every bar: the open, high, low and close of the last finished day, week or month, the high and low of the running one so far, and the distance from the close to the previous high and low in units of a daily ATR, so one rule works on EURUSD and on gold.
Where a day starts is a choice. The default is 17:00 New York, daylight saving included, where forex turns the day: Sunday evening is the start of Monday, so Monday's previous day is Friday. This is the same trading day the built in pivots and VWAP use with their session input on 17:00 New York, so this indicator and the chart agree. The other choices are 00:00 UTC and a custom start on any clock, for an exchange's close (16:00 America/New_York for US stocks, 17:30 Europe/Berlin for Xetra). Weeks start on Monday, months are the trading day's calendar month. Pivot points themselves are in the indicator catalogue (ctx.ind("pivots")), drawn on the chart; use this plugin for the raw levels and the ATR distance.
Parameters
| Name | Type | Default | Range or options | Description |
|---|---|---|---|---|
period | choice | "day" | day, week, month | The period the levels come from. Weeks start on Monday, months are the trading day's month. |
day_start | choice | "ny" | ny, utc, custom | Where a day starts: 17:00 New York (as the built in pivots and VWAP), 00:00 UTC, or start in tz. |
start | text | "17:00" | Custom day start only: a clock time like 16:00. A day starting at or after noon carries the date it ends on, one starting before noon the date it starts on. | |
tz | text | "America/New_York" | Custom day start only. A time zone name (IANA), like Europe/Berlin or America/New_York. | |
atr_period | int | 14 | min 1, max 200 | Finished trading days in the daily ATR (Wilder's smoothing). |
Use it in a strategy
pythonlv = ctx.plugin_indicator("prior_period_levels", "levels", {"period": "day"})
if lv is not None and lv.dist_high_atr is not None:
if lv.new_period:
ctx.signal("EXIT")
elif lv.dist_high_atr > 0.25:
ctx.signal("LONG")
elif lv.dist_low_atr < -0.25:
ctx.signal("SHORT")The indicator library has this as prior_levels: ctx.ind("prior_levels", period="day", session="ny") reads the previous and the running open, high, low and close, and the chart, Blocks, Rust and the Rust core have it too. This template stays as an example of a plugin indicator; only it has the daily ATR distances and a custom day start in any time zone.
What it provides
prev_open, prev_high, prev_low, prev_closeValue | The last finished period's open, high, low and close; None until the first period in the data has finished. |
valueValue | The same as prev_close. |
open, high, lowValue | The running period's open, and its high and low so far, this bar included. |
new_periodValue | True on the first bar of a new period. |
atrValue | Wilder's ATR of finished trading days (same day start), never the running day; None until atr_period + 1 days have finished. |
dist_high_atr, dist_low_atrValue | (close - prev_high) / atr and (close - prev_low) / atr: positive above the level, negative below; None while either part is missing. |
Limits
- A period counts from its first bar in the data: when the history starts in the middle of a day, that partial day is the first previous day.
- The levels come from the run's own bars (mid prices). Holidays are not known: a day with a few bars is a day like any other.
- A plugin indicator is not drawn on the chart and is not available in Blocks, Pine, Rust or C#; it runs on the run's own instrument only.