Strategy Samples
Use these snippets to integrate your TradingView strategies with Algo Trade Analytics.
Minimal Template
Section titled “Minimal Template”Ideal for adding to an existing strategy.
//@version=6strategy("Minimal Integration", overlay=true)
// 1. ConfigurationauthKey = input.string("YOUR_AUTH_KEY", "Webhook Auth Key")qty = input.int(10, "Quantity")
// 2. Helper for Webhook Message// Captures ticker, direction, and current price for slippage analysiscreateMessage(direction) => '{"auth_key":"' + authKey + '","ticker":"' + syminfo.ticker + '","direction":"' + direction + '","marketPrice":' + str.tostring(close) + ',"qty":' + str.tostring(qty) + '}'
// 3. Example Entryif ta.crossover(ta.sma(close, 10), ta.sma(close, 20)) strategy.entry("Long", strategy.long, alert_message=createMessage("long"))
// 4. Example Exitif ta.crossunder(ta.sma(close, 10), ta.sma(close, 20)) strategy.close("Long", alert_message=createMessage("short"))Advanced Template (with Stop/Limit)
Section titled “Advanced Template (with Stop/Limit)”For strategies using specific order types.
//@version=6strategy("Advanced Integration", overlay=true)
authKey = input.string("YOUR_AUTH_KEY", "Webhook Auth Key")
// Helper for Limit OrderscreateLimitMessage(direction, limitPrice) => '{"auth_key":"' + authKey + '","ticker":"' + syminfo.ticker + '","direction":"' + direction + '","orderType":"limit","limitPrice":' + str.tostring(limitPrice) + ',"marketPrice":' + str.tostring(close) + '}'
// Entry with Limitif ta.crossover(ta.sma(close, 10), ta.sma(close, 20)) buyPrice = close * 0.99 strategy.entry("Long", strategy.long, limit=buyPrice, alert_message=createLimitMessage("long", buyPrice))Tips for Success
Section titled “Tips for Success”- Use
str.tostring(close): Always include the current price in your webhook message to enable slippage analysis. - Test with Small Qty: Start with 1 share or a paper account to verify the connection.
- Check Dashboard: Visit the Trade Analysis dashboard immediately after an alert fires to see the match results.