Automation
Strategy Setup
Build complete automated trading strategies with entry and exit signals, risk management, and a step-by-step testing workflow.
A complete trading strategy requires both entry and exit logic. This guide covers setting up end-to-end automation with proper risk management.
Entry + Exit Approaches
Separate Webhooks
Use one webhook for entries and another for exits. This keeps signal types organized and makes the Alerts page easier to filter.
Single Webhook
Use one webhook for all signals. The parser handles all command types through the same endpoint.
Multi-Command Signals
Use semicolons to chain entry and exit in a single signal. This ensures both commands execute together with no gap:
CLOSEALL;BUY,EURUSD,VOL=0.01,SL=100,TP=200Close all existing positions, then immediately open a new one:
CLOSE,{{ticker}};SELL,{{ticker}},VOL=0.01,SL=100,TP=200Risk Management
Always Use Stop Loss
Every entry signal should include a stop loss. Use TPSLTYPE=PIPS for pip-based distances, or use price values directly (the default):
BUY,EURUSD,VOL=0.01,SL=50,TP=100,TPSLTYPE=PIPSBUY,XAUUSD,VOL=0.1,SL=2000.00,TP=2100.00Risk-Based Position Sizing
Use the RISK parameter to size your position based on account balance instead of fixed lots:
BUY,EURUSD,RISK=1,SL=50,TP=100,TPSLTYPE=PIPSThis risks 1% of your account balance with a 50-pip stop loss. Trade W zrd calculates the appropriate lot size automatically.
Multi-Symbol Strategies
Use the {{ticker}} placeholder for strategies that work across multiple symbols. One TradingView alert template works on any chart:
BUY,{{ticker}},VOL=0.01,SL=100,TP=200CLOSE,{{ticker}}BREAKEVEN,{{ticker}},OFFSET=0.0010CLOSEALL Filters for Risk Management
Use CLOSEALL with filters to manage portfolio-level exits:
CLOSEALL,EURUSD,POSITIVE=trueClose only winning positions to lock in profits:
CLOSEALL,XAUUSD,NEGATIVE=trueClose only losing positions to stop the bleeding:
CLOSEALL,EURUSD,PENDING=trueCancel all pending orders before a news event:
CLOSEALL,EURUSD,POSITIONS=trueLAYER_CLOSE for Volume-Based Exits
When you need to close a specific lot amount across multiple open positions:
LAYER_CLOSE,EURUSD,VOL=0.05This closes enough trades to total 0.05 lots, starting from the oldest. Add SIDE=BUY or SIDE=SELL to filter by direction:
LAYER_CLOSE,EURUSD,VOL=0.03,SIDE=BUYBREAKEVEN to Protect Profits
Move your stop loss to entry price (or entry plus an offset) to protect profits on winning trades:
BREAKEVEN,EURUSDBREAKEVEN,EURUSD,OFFSET=0.0010BREAKEVEN,EURUSD,OFFSET=0.0005,SIDE=BUYMagic Numbers
Use MAGIC to tag trades from a specific strategy. This lets you selectively close or modify only trades from that strategy:
BUY,EURUSD,VOL=0.01,SL=100,TP=200,MAGIC=101Later, close only these trades:
CLOSE,EURUSD,MAGIC=101Direction Filtering
When closing, you can filter by direction to only close one side:
CLOSE,EURUSD,SIDE=BUYThis only closes BUY positions on EURUSD, leaving any SELL positions open.
Testing Workflow
- Build in Playground - Use Automation > Playground to construct and verify your signal format
- Test on demo - Connect a demo account to the webhook and send test signals
- Verify in Alerts - Check Automation > Alerts to confirm signals were received and executed
- Check Trade History - Verify trades appear in Automation > History
- Go live - Once satisfied, add your live account to the webhook
Complete Strategy Example
A breakout strategy with entry, breakeven, partial close, and exit - all pointing to the same webhook URL:
Alert 1 - Entry:
BUY,{{ticker}},RISK=1,SL=50,TP=150,TPSLTYPE=PIPS,MAGIC=201Alert 2 - Move to breakeven (triggered when price moves in profit):
BREAKEVEN,{{ticker}},OFFSET=0.0005,MAGIC=201Alert 3 - Partial close (take some profit):
CLOSE,{{ticker}},PERCENT=50,MAGIC=201Alert 4 - Full close (exit remaining):
CLOSE,{{ticker}},MAGIC=201The MAGIC=201 tag ensures only trades from this strategy are affected by the exit alerts. All four alerts use the same webhook URL.







