Studio · Product guide
Write strategies in Python (Merit Strategy SDK)
How a Studio strategy reads bars and settings and places stop-protected orders.
Step-by-step instructions
Screenshots are examples. Your balances, limits, availability and status may differ.
Every strategy is one Python function, on_event(event, state). Studio calls it after each closed bar (and on live quotes when a bot runs it), and it returns a list of orders, or [] to do nothing.
Read prices from event["history"][symbol]: up to the last 500 closed bars, each with open, high, low, close and volume. The newest bar is the last item, and the code never sees a future bar.
Put the numbers you want to tune in inputs (integer, number, true/false or a list of options, up to 16) and read them with event["inputs"]["fast"]. Inputs with a minimum and maximum can be optimized.
Return a target order: action "target" with the symbol, a weight and a stopPct, for example weight 0.03 and stopPct 2. weight is the position size as a share of equity (negative is short, 0 is flat) and stopPct is the protective stop in percent (0.5 to 10). Studio only trades the difference from what you already hold.
Keep values between bars in state, a dictionary that persists, for example state["side"] = 1. Python math and statistics are always available; numpy, pandas, scipy and scikit-learn are available when Studio lists them. There is no network or file access.
Start from a template on the Studio home page, or ask Merit AI to write or change the code. Open the Script tab to read or edit it, then run a backtest.
If something goes wrong
A backtest with 0 trades means the strategy never returned a non-zero weight: check that the history is long enough for its indicator periods. An error in the code stops the run and names the line; ask Merit AI to fix it.
Contact support