Creating a Strategy
This guide walks you through creating a trading strategy from scratch using the MangroveAI API. By the end, you will have a saved strategy ready for backtesting.Prerequisites
Before you begin, make sure you have:- An authentication token. All API calls require a Bearer token. See the Authentication guide for how to obtain one.
- A basic understanding of signals. You should know the difference between TRIGGER and FILTER signals. If not, read Understanding Signals first.
Step 1: Browse available signals
Start by exploring what signals are available. The signals endpoint returns all 136 active signals with their metadata, parameters, and valid ranges.Step 2: Choose your entry signals
A strategy entry requires exactly 1 TRIGGER and 1 FILTER. For this walkthrough, we will build a trend-following strategy for ETH:- TRIGGER:
macd_bullish_cross— enters when the MACD line crosses above the signal line - FILTER:
is_above_sma— confirms the price is above the 50-period Simple Moving Average
macd_bullish_cross signal requires three parameters:
window_fast(int, range 1-100) — fast EMA periodwindow_slow(int, range 1-200) — slow EMA periodwindow_sign(int, range 1-100) — signal line period
is_above_sma signal requires one parameter:
window(int, range 1-1000) — SMA period
Step 3: Choose exit signals (optional)
Exit signals follow the same pattern: 1 TRIGGER with an optional FILTER. For this strategy, we will add an explicit exit:- Exit TRIGGER:
macd_bearish_cross— exits when the MACD line crosses below the signal line
exit array), the strategy will rely entirely on the built-in stop-loss, take-profit, and time-based exit rules from the execution_config.
Step 4: Create the strategy
Now assemble everything into aPOST /api/v1/strategies request. The canonical format uses top-level entry and exit arrays.
execution_config and execution_state:
You did not provide
execution_config or execution_state in the request. The API automatically populates both with defaults from trading_defaults.json. You can override any field by including it in your request. See the Risk Management guide for details on every field.Step 5: Verify the strategy
Retrieve your newly created strategy to confirm everything was saved correctly:- Status:
inactive(the default for new strategies) - Entry signals:
macd_bullish_cross(TRIGGER) +is_above_sma(FILTER) - Exit signals:
macd_bearish_cross(TRIGGER)
Common validation errors
If your request is rejected, check for these common issues:| Error | Cause | Fix |
|---|---|---|
Missing required fields: name, asset | Missing top-level fields | Include both name and asset in the request body |
| Multiple TRIGGERs in entry | Entry has 2+ signals with signal_type: "TRIGGER" | Keep exactly 1 TRIGGER and 1 FILTER for entry |
| Multiple FILTERs in entry | Entry has 2+ signals with signal_type: "FILTER" | Keep exactly 1 TRIGGER and 1 FILTER for entry |
Signal 'xyz' not found | Invalid signal name | Check the name against GET /api/v1/signals |
What to do next
Your strategy is created and ready to test. Continue with:- Run a backtest to test your strategy against historical data
- Tune risk parameters to adjust stop-loss, position sizing, and cooldowns
- Use the AI Copilot to build strategies conversationally instead of manually