request.* Function Reference
Reference for request.security and request.seed in ATK PyneScript V6 — multi-timeframe resampling and seed-backed auxiliary data flows.
request.* Overview#
The request namespace provides two functions for bringing external or resampled data into a frame builder. Both belong exclusively in the compute stage — never in build_trade_frame or build_visuals.
request.security#
Resamples the base frame to a higher timeframe and runs a computation on the result.
| Parameter | What it controls | How to choose it |
|---|---|---|
frame | The base dataset to resample from. | Use the clean frame already being computed in the current builder. Do not pass a partially mapped trade frame or a render-stage slice. |
timeframe | The target aggregation level. | Choose only the timeframe that actually changes the script meaning. If the user cannot explain why HTF context matters, the script probably does not need request.security. |
expr | The HTF computation to run on the resampled frame. | Keep it narrow and single-purpose. A small lambda for one HTF EMA is easier to reason about than a deeply nested pipeline. |
fill_method | How the HTF result is aligned back to the base frame. | Use forward-fill when the last confirmed HTF value should remain active until the next HTF bar arrives. Use backward-fill only when the semantic meaning really demands it. |
Stage-Correct Usage#
import pandas as pd
from source import input, request, strategy, ta
strategy("Annotated MTF Strategy", overlay=True, process_orders_on_close=True, max_bars_back=240)
confirm_tf = input.timeframe("15m", title="Confirm TF", key="confirm_tf")
trend_length = input.int(34, title="HTF Trend EMA", key="trend_length", minval=1)
def build_signal_frame(df: pd.DataFrame, params: dict | None = None) -> pd.DataFrame:
frame = df.copy().reset_index(drop=True)
merged = {
"confirm_tf": str(confirm_tf),
"trend_length": int(trend_length),
} | dict(params or {})
# request.security belongs in the signal builder because it is part of computation.
htf_trend = request.security(
frame,
str(merged.get("confirm_tf", "15m") or "15m"),
lambda x: ta.ema(x["close"], int(merged.get("trend_length", 34) or 34)),
)
frame["htf_trend"] = htf_trend
frame["trend_ok"] = (frame["close"] >= htf_trend.fillna(frame["close"]))
return frameWrong vs Right#
# Wrong: trade mapping should not contain computation.
def build_trade_frame(signal_df, params=None, styles=None):
signal_df = signal_df.copy()
signal_df["htf"] = request.security(signal_df, "1h", lambda x: ta.ema(x["close"], 34))
return build_mapped_trade_frame(signal_df)
# Right: compute in the signal builder, then map only.
def build_signal_frame(df, params=None):
frame = df.copy().reset_index(drop=True)
frame["htf"] = request.security(frame, "1h", lambda x: ta.ema(x["close"], 34))
frame["buy_signal"] = (frame["close"] >= frame["htf"].fillna(frame["close"]))
return frame
def build_trade_frame(signal_df, params=None, styles=None):
return build_mapped_trade_frame(signal_df)Calling request.security inside build_trade_frame or build_visuals turns a compute helper into a mapping-stage or render-stage dependency. Always place it in build_indicator_frame or build_signal_frame.
request.seed#
Injects structured inline data into a frame column without requiring a live market feed. Use it when auxiliary data is computed in Python and needs to be aligned with the frame.
from source import indicator, input, request
indicator("Annotated Request Seed", overlay=False)
seed_window = input.int(4, title="Seed Window", key="seed_window", minval=2)
def build_indicator_frame(df, params=None):
frame = df.copy().reset_index(drop=True)
window = max(int((params or {}).get("seed_window", seed_window) or seed_window), 2)
seeded_source = {
"seeded_close": frame["close"].rolling(window, min_periods=1).mean().round(4).tolist(),
"seeded_bias": [
"bullish" if close_val >= open_val else "bearish"
for open_val, close_val in zip(frame["open"], frame["close"])
],
}
frame["seeded_close"] = request.seed(seeded_source, "seeded_close")
frame["seeded_bias"] = request.seed(seeded_source, "seeded_bias")
return frameSee also: