SuperTrend Strategy
The SuperTrend strategy is a well-established and commonly utilized approach to trading has been optimized for use with PineConnector, a software that links TradingView to MetaTrader brokers and prop firms.
This trend-following method can be employed across multiple markets, including forex, stocks, futures, cryptocurrencies, and other financial assets.
With PineConnector, you can fully automate the SuperTrend strategy, making it a suitable solution for both day and swing traders. This allows you to streamline your trading process, freeing up time, minimizing the risk of human error and eliminating emotion in your trading.
Implementation of the Strategy
- PineConnector EA running on your MetaTrader terminal — you should see your license details printed on your chart.
- Close on Reverse EA setting set as “On — Hedging”.
1. Create a new script
At the bottom of your TradingView tab, click "Pine Editor" → “Open” → “Strategy”.
2. Attach the code
Remove the default code generated, and attach the following code:
//@version=5
strategy('Supertrend Strategy - PineConnector', overlay=true)
LicenseID = 601234567890 // 1. change to your PineConnector License ID (required)
riskvalue = input.int(1, 'Risk Value') // 2. Change the risk value (optional)
atrPeriod = input(10, 'ATR Length') // 3. Change the ATR length/period (optional)
factor = input(3, 'Factor') // 4. Change the ATR factor/multiplier (optional)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, 'Up Trend', color=color.new(color.green, 0), style=plot.style_linebr)
downTrend = plot(direction < 0 ? na : supertrend, 'Down Trend', color=color.new(color.red, 0), style=plot.style_linebr)
fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
if ta.change(direction) < 0
strategy.entry('Long', strategy.long)
alert(str.tostring(LicenseID)+',buy,' + syminfo.ticker + ',risk=' + str.tostring(riskvalue), alert.freq_once_per_bar_close)
if ta.change(direction) > 0
strategy.entry('Short', strategy.short)
alert(str.tostring(LicenseID)+',sell,' + syminfo.ticker + ',risk=' + str.tostring(riskvalue), alert.freq_once_per_bar_close)
plotshape(ta.change(direction) < 0, style=shape.labelup, location=location.belowbar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Buy', textcolor=color.new(color.white, 0))
plotshape(ta.change(direction) > 0, style=shape.labeldown, location=location.abovebar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Sell', textcolor=color.new(color.white, 0))
601234567890
, input your PineConnector License ID you’re entered in the PineConnector EA. It is a long string starting with a 6.
Basic Optional Change:
- Instead of
riskvalue
being 1, you may increase or decrease the lot size per trade. - How the EA processes this
riskvalue
depends on your Volume Type in your EA. - the default setting of “Lots” will open 1 volume/lot each trade with
riskvalue
of 1 — use this option if you are a beginner.
Advanced Optional Changes:
- Instead of
atrPeriod
of 10, you may increase or shorten the ATR period. - Instead of
factor
of 3, you may tweak the ATR multiplier to your desired value.
3. Save the code and Add Strategy to the Chart
After attaching and amending the above code, click “Save” then “Add to chart” to apply the strategy to your current chart. You should be able to see the SuperTrend entries indicated on the chart:
4. Create alerts
On your desired instrument and timeframe create the alerts.
To create an alert, press Alt+A (Windows) or Option+A (Mac), and configure your alert as follows:
Component | Configuration |
Condition | Supertrend Strategy
alert() function calls only |
Webhook URL | For PineConnector v2:
https://pineconnector.net/webhook/
For PineConnector v3:
https://webhook.pineconnector.com |
Alert name,
Notify on app | “Alert name” does not matter
”Notify on app” selection does not matter as well |
After proper alert configuration, click “Create”. An active alert will appear under your “Alerts” tab.
5. Confirm triggered alerts
When entry conditions are met, an alert will fire. You will see an entry in your TradingView’s Alerts Log indicating the time, alert message, instrument and timeframe it fired based on.
After a alert fires, you should see a corresponding trade entry as per the alert message.
6. Tailor your alerts (optional)
Consider adding a stop-loss, a comment with the position, or even a spread filter.
Component | Relevant Guide |
- Discover more about the proper way to write the alert messages
- Add more components such as a spread filter | |
- Utilise a different Volume Type
- Implement a Daily Profit or Loss | |
- Include additional parameters such as stop-loss
- Implement dynamic symbols and values |