Your First Strategy
Build a simple moving average crossover strategy step by step.
Let's build a classic moving average crossover strategy together. This will teach you the fundamentals of AlgoHive's visual strategy builder.
What We're Building
A simple EMA crossover strategy that:
- Buys when the fast EMA crosses above the slow EMA
- Sells with a stop loss and take profit
Step 1: Create a New Strategy
- Navigate to Strategies in the sidebar
- Click Create New Strategy
- Name it "My First Strategy"
- You'll enter the Strategy Studio
Step 2: Add a Data Source
Every strategy needs market data to analyze.
- In the workflow editor, you'll see a Data Sources section
- Click Add Data Source
- Configure:
- Alias:
btc(a short name to reference this data) - Type: Exchange
- Symbol: BTC-USD
- Timeframe: 4h (4-hour candles)
- Alias:
- Click Add
You now have a data source node showing BTC-USD price data with columns: open, high, low, close, volume.
Step 3: Add Analysis Blocks
Now let's calculate moving averages and detect crossovers.
- Click Add Analysis in the toolbar
- Select Advanced Block (for multiple outputs)
- Name it
signals - Add these outputs:
fast_ema: EMA(btc.close, 9)
slow_ema: EMA(btc.close, 21)
cross_up: cross_above(fast_ema, slow_ema)This creates:
- A 9-period EMA of the closing price
- A 21-period EMA of the closing price
- A signal that fires when the fast crosses above the slow
Step 4: Add an Entry Rule
- Click Add Entry in the toolbar
- Configure:
- Direction: Long
- Market:
btc(your data source) - When:
signals.cross_up
- Click Add
Now your strategy will enter a long position whenever the fast EMA crosses above the slow EMA.
Step 5: Add Risk Management
- Click Add Manage Rule in the toolbar
- Add a Stop Loss:
- Type: Stop Loss
- Level: 5% (percentage from entry)
- Add another rule for Take Profit:
- Type: Take Profit
- Level: 3R (3x the risk)
Step 6: Connect the Manage Rules
Drag from your Entry node to each Manage node to link them. This tells AlgoHive which rules apply to which entries.
Step 7: Backtest
- Click Lab in the top navigation
- Set your backtest parameters:
- Start Date: 1 year ago
- End Date: Today
- Initial Equity: $10,000
- Click Run Backtest
- Review results:
- Equity curve
- Win rate
- Max drawdown
- Individual trades
Step 8: Iterate
Based on your backtest results, you might want to:
- Adjust EMA periods
- Add filters (e.g., only trade when RSI < 70)
- Change stop loss/take profit levels
- Add multiple timeframes
Step 9: Paper Trade
When happy with backtest results:
- Click Deploy
- Select Paper mode
- Configure alerts (optional)
- Click Deploy
Your strategy is now running in paper mode, tracking real market conditions without risking real money.
Step 10: Go Live
After validating in paper mode:
- Go to Deploy tab
- Click Switch to Live
- Confirm you understand the risks
- Your strategy is now trading with real funds
Summary
You've built a complete trading strategy:
- Data Source — BTC-USD 4h candles
- Analysis — EMA crossover detection
- Entry — Long on cross_above signal
- Risk — Stop loss and take profit
Next Steps
- Explore the Studio — Learn all the features
- More Indicators — Beyond EMAs
- Advanced Strategies — More complex examples