Skip to content
Algo Trade Analytics Docs

Strategy Samples

Use these snippets to integrate your TradingView strategies with Algo Trade Analytics.

Ideal for adding to an existing strategy.

//@version=6
strategy("Minimal Integration", overlay=true)
// 1. Configuration
authKey = 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 analysis
createMessage(direction) =>
'{"auth_key":"' + authKey + '","ticker":"' + syminfo.ticker + '","direction":"' + direction + '","marketPrice":' + str.tostring(close) + ',"qty":' + str.tostring(qty) + '}'
// 3. Example Entry
if ta.crossover(ta.sma(close, 10), ta.sma(close, 20))
strategy.entry("Long", strategy.long, alert_message=createMessage("long"))
// 4. Example Exit
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 20))
strategy.close("Long", alert_message=createMessage("short"))

For strategies using specific order types.

//@version=6
strategy("Advanced Integration", overlay=true)
authKey = input.string("YOUR_AUTH_KEY", "Webhook Auth Key")
// Helper for Limit Orders
createLimitMessage(direction, limitPrice) =>
'{"auth_key":"' + authKey + '","ticker":"' + syminfo.ticker + '","direction":"' + direction + '","orderType":"limit","limitPrice":' + str.tostring(limitPrice) + ',"marketPrice":' + str.tostring(close) + '}'
// Entry with Limit
if 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))
  • 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.