9.1 Creating Alerts
In Pinescript, you can create alerts based on specific conditions. Alerts can be triggered when a condition is met, and you can receive notifications through various methods, such as email or SMS or directly to the exchange using Autoview.
9.2 Alert Triggers
To create an alert trigger, you can use an IF statement with the result not only plotting on your chart for backtesting, but you can have the alert trigger and send your provided alert_message whereever you want.
In this example, we would be triggering an alert that tells Autoview to long or short with 10% of our balance at market.
smaValue = ta.sma(close, 14)
rsiValue = ta.rsi(close, 14)
longCondition = ta.crossover(rsiValue, 30) and ta.crossover(close, smaValue)
shortCondition = ta.crossunder(rsiValue, 70) and ta.crossunder(close, smaValue)
if longCondition
strategy.entry("Long", strategy.long, alert_message="b=long q=10% t=market")
if shortCondition
strategy.entry("Short", strategy.short, alert_message="b=short q=10% t=market")
9.3 Setting up Notifications
After defining alert triggers in your script, you can set up notifications in TradingView's user interface. Navigate to the "Alerts" tab, click on "Create Alert", select your custom strategy, put {{strategy.order.alert_message}}. This tells Tradingview to grab our alert_message="" from the specific condition and pass that as the alert is triggered. Configure the notification method (email, SMS, etc.) and save the alert.
Notice that we put {{strategy.order.alert_message}}. This tells Tradingview to grab our alert_message="" from the specific condition and pass that as the alert is triggered.
Comments
0 comments
Please sign in to leave a comment.