Skip to main content

Automate TradingView Strategy

TL;DR​

🔥 Example TradingView PineScript Strategy here​

⚠️ Note that this only works if the strategy is created with TradingView & API template that implements on_tradingview_signal which uses our Python library to place orders based on the received signal (see below)

Step 1: Create TradingView Strategy on the Strategy page​

Step 2: Here are the default messages for SPOT (can change to USDⓈ-M Futures)​

Step 2.1 (optional): Change the Strategy Type and Pair (default is SPOT)​

Step 3: Generate the corresponding messages by configuring Order Type, Qty Type and Client Order ID​

👉 See detailed API spec here 👀

  • Order Type: MARKET | LIMIT, default to MARKET

  • Qty Type: Percent | Fixed; default to 100 Percent

  • Client Order ID: Client order ID to uniquely identify order; default to {{strategy.order.id}}


  • TP/SL: Prices for Take Profit and Stop Loss orders - only available for opening position in USDⓈ-M Futures

Step 4: Copy and paste these messages to your Pinescript​

  • Webhook URL: https://api.crypto-arsenal.io/trading-signal/webhook

Step 5: Use the message in Pinescript with alert call or alert_message on order fill events​

👉 Example TradingView Strategy here 📝​

  1. Manually trigger alert calls i.e alert("message")

  2. Trigger alerts on order fill events with alert_message on strategy.close(), strategy.entry(), strategy.exit() and strategy.order()

    a. ⚠️ Need to fill the Alert Creation box with {{strategy.order.alert_message}}

💡 Strategy placeholder i.e {{close}} wouldn't work in these strategy alert calls, you need to use variables in your strategies like

💡 {{ }} placeholder 在pinescript 裡不會有值 需要用 + " " +

  • MA Example

    • alert_message = "Stop-buy executed (stop was " + str.tostring(high) + ")"
  • Stop loss and Take Profit Example

    • alert('{"action":"openLong", "percent":"100","profit":"' + 
      str.tostring(strategy.position_avg_price * (1 + 0.1)) +
      '","loss":"' + str.tostring(strategy.position_avg_price * (1 - 0.1)) + '"}')

Step 6: Create an alert on the strategy on TradingView​


Remember to fill the message with {{strategy.order.alert_message}} if alerts are triggered with order fill events

Step 7:​

  • You will now go back to the Crypto Arsenal page and head to Record and launch a Simulation to test-drive before launching your bot for live trade.

Step 8:​

  • Once the TradingView alert triggers, you can see the buy entry on the chart along with stats and logs on the side

If you want custom action or logic...​

  • You can customize with Python in the Editor by updating the def on_tradingview_signal(self, signal, candles): callback

If you have an Indicator...​