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, where you should see:
- Your license details printed on your chart on MT4/5
- Trading Account Connected on your Licensing Dashboard
- Close on Reverse EA setting set as “On — Hedging”.
1. Create a new strategy script
At the bottom of your TradingView tab, click "Pine Editor" → “Open” → “New strategy”.
2. Configure Script
2.1. Apply SuperTrend Strategy 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')
factor = input(3, 'Factor')
[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))
2.2. Update License ID
In the code, instead of the default License ID of 601234567890, change it to your License ID found in your PineConnector Portal. It should be a long string of numbers, usually starting with a 6 or 7.
LicenseID = 601234567890 // 1. change to your PineConnector License ID (required)
2.3. Update Risk Parameter (Optional)
In the code, you can also tweak the risk parameter whereby using a higher value will result in a larger volume per trade. The volume computed will be based on your EA Setting’s Volume Type.
riskvalue = input.int(1, 'Risk Value') // 2. Change the risk value (optional)
2.4. Save, and Add to Chart
Once you have updated your License ID, save the strategy script, and add it to chart.
3. Orientation
Once you have successfully added the SuperTrend strategy on your chart, you should be able to see the following:
3.1. Upper Section
- Symbol, timeframe and data provider → For this example, we are have EURUSD chart running on the 24 hour chart, where data feed is by Pepperstone.
- SuperTrend Strategy indicated on the top left corner, primarily,
- Click the eye icon to show/hide the script’s interface
- Click the
{ }
to make edits to the code - Click the bin icon to remove the script from your chart
- On the chart, you will be able to see the strategy entries (in blue arrows, such as PineConnector Buy and PineConnector Sell)
- For this strategy, with Close on Reverse (On — Hedging), a buy position will close first upon an incoming sell signal, followed by the sell position opening, and vice-versa.
3.2. Lower Section
- When you attach a strategy to a chart, you’ll automatically be directed to the “Strategy Tester” tab, where you can view the backtest or historical performance of the strategy based on the symbol, timeframe, and data provider’s price feed.
- Yes, profitability of a strategy may (and likely) differ based on the data feed provider of your choice (try it!)
- The profitability on EURUSD is generally poor since the SuperTrend strategy is a trend-based system and EURUSD-24H is typically in a “ranging” or “horizontal” market.
4. Create Alerts
To change the timeframe to 1 minute, simply press 1 and hit Enter.
On your desired instrument and timeframe, such as EURUSD (1 minute) or GBPJPY (15 minutes), create the alerts. Press Alt+A (Windows) or Option+A (Mac), and configure your alert as follows:
4.1. Settings Tab
In the alert popup, under Settings
, select the SuperTrend Strategy
and alert() function calls only
. The alert name can be left as-is, or change it to something of your choice—it’s not important.
4.2. Notifications Tab
Now, click on the Notifications
tab, enable Webhook URL and add the following URL:
https://webhook.pineconnector.com
Once you’ve added the webhook URL, click Create
.
For other components such as Notify in app, Show toast notification, Send email, Play sound, and Send plain text, these options are not required, though you can have them activated as per your preference.
To apply the updated code, delete the old alerts and create new ones.
5. Entry Conditions Met: Trigger!
When SuperTrend conditions are met, an alert sends data to the PineConnector server, which relays it to your MetaTrader terminal. The EA processes this based on your settings, triggering actions like opening a buy position for EURUSD.
With this script, you will only need 1 alert to trigger both buy and sell entries for the current symbol and timeframe (e.g., EURUSD, 1 minute).
5.1. Confirmation on TradingView Alerts Log
When entry conditions are met, you will see an entry in your TradingView’s Alerts Log indicating the time, alert message, instrument and timeframe it fired based on.
5.2. Confirmation on Signal Log
The corresponding alert will result in a new entry in your PineConnector Portal, under Signal Logs.
If you do not see a log entry created, you could have used the incorrect webhook address, or configured the alert message incorrectly.
5.3. Confirmation on MT4/5
After an alert fires, you should see a corresponding trade entry as per the alert message.
6. Done Done!
Once you see the trade open on your MetaTrader 4/5 terminal, you’ve successfully implemented the SuperTrend strategy. Now, wait for the opposite signal to trigger, which will automatically close the current position and open a new one based on the updated signal.
We hope this guide has been helpful in implementing the SuperTrend strategy.
On this page
- SuperTrend Strategy
- Implementation of the Strategy
- 1. Create a new strategy script
- 2. Configure Script
- 2.1. Apply SuperTrend Strategy Code
- 2.2. Update License ID
- 2.3. Update Risk Parameter (Optional)
- 2.4. Save, and Add to Chart
- 3. Orientation
- 3.1. Upper Section
- 3.2. Lower Section
- 4. Create Alerts
- 4.1. Settings Tab
- 4.2. Notifications Tab
- 5. Entry Conditions Met: Trigger!
- 5.1. Confirmation on TradingView Alerts Log
- 5.2. Confirmation on Signal Log
- 5.3. Confirmation on MT4/5
- 6. Done Done!