Skip to main content

Studio · Product guide

Write strategies in Python (Merit Strategy SDK)

How a Studio strategy reads bars and settings and places stop-protected orders.

Before you begin

A Studio project. Python experience helps but is not required: Merit AI writes and edits the code for you.

Step-by-step instructions

Screenshots are examples. Your balances, limits, availability and status may differ.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

What you should see

You can read a strategy’s code, change its settings and know what each order does.

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
Each call has 8 seconds, 512 MB of memory and one CPU. Orders execute on the next event and backtests model fills from OHLC bars, so results are not tick-accurate.
Open StudioProduct manual · Follow the current status and rules shown in your account