Alert Payloads
strategy_alert_message template plus per-row tag, comment, and alert_message metadata fields.
Alert Templates and Human-Readable Metadata#
Current strategy docs should teach both the script-level template and the row-level metadata. Use
strategy_alert_message(...) for the reusable shell, and keep per-row context in tag, comment, and
alert_message.
from source import build_mapped_trade_frame, strategy, strategy_alert_message, ta
strategy("Alert Template Strategy", overlay=True, process_orders_on_close=True)
strategy_alert_message("{{ticker}} {{strategy.order.id}} {{strategy.order.action}}")
def build_signal_frame(df, params=None):
frame = df.copy().reset_index(drop=True)
ema_fast = ta.ema(frame["close"], 9)
ema_slow = ta.ema(frame["close"], 21)
buy_signal = ta.crossover(ema_fast, ema_slow).fillna(False)
frame["entry_side"] = buy_signal.map({True: "BUY", False: ""})
frame["entry_price"] = frame["open"]
frame["quantity"] = 1.0
frame["size_pct"] = 0.0
frame["tag"] = buy_signal.map({True: "EMA-LONG", False: ""})
frame["alert_message"] = buy_signal.map({True: "ema crossover fired", False: ""})
return frame
def build_trade_frame(signal_df, params=None, styles=None):
return build_mapped_trade_frame(signal_df)