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 toMARKET
-
Qty Type:
Percent
|Fixed
; default to100 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 πβ
-
Manually trigger
alert
calls i.ealert("message")
-
Trigger alerts on order fill events with
alert_message
onstrategy.close()
,strategy.entry()
,strategy.exit()
andstrategy.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...β
-
See this article https://help.crypto-arsenal.io/en/articles/6418859-autumate-tradingview-indicator
-
Or this article for API Trading https://help.crypto-arsenal.io/en/articles/6510420-api-trading