Skip to content
Docs
Open Portal
Copy the page manually

Your browser did not allow direct clipboard access. Select and copy the Markdown below.

SuperTrend Strategy

Add the published SuperTrend example to TradingView, connect its buy and sell alerts, and verify the result on a demo account.

This walkthrough connects SuperTrend’s direction changes to PineConnector. You will add the published Pine Script v5 example, create one alert for its buy and sell messages, then check the order in MetaTrader.

The code below retains the original Pine v5 version and its settings-dependent sizing. If you choose to upgrade it, follow Convert Pine Script versions and verify the changed script separately. A language upgrade does not establish that alerts, sizing or reversals behave the same way.

Before you begin

The published walkthrough uses Close on Reverse → On — Hedging: an opposite entry signal closes the relevant opposite position before opening the new direction. Check Close on Reverse in the EA guide for its scope and interaction with your other settings.

MetaTrader EA settings showing Close on Reverse set to On - Hedging Enlarge
Published EA-settings example from 2024. Other settings in the screenshot are not a recommendation for your account.
Published EA-settings example from 2024. Other settings in the screenshot are not a recommendation for your account.Open original
MetaTrader EA settings showing Close on Reverse set to On - Hedging

These EA input changes apply to a self-hosted terminal. For Edge, confirm the hosted reversal and sizing settings through Portal or Support; changing a local EA does not change Edge. If Signal Authentication is enabled, add your configured secret= privately to both generated alert messages before creating the alert.

Open Pine Editor and create a New strategy. Replace the generated sample with the complete code below.

TradingView Pine Editor with Open and New strategy highlighted Enlarge
Published editor example from 2024. The location of editor menus may change.
Published editor example from 2024. The location of editor menus may change.Open original
TradingView Pine Editor with Open and New strategy highlighted
SuperTrend Strategy — complete Pine v5 example
TradingView → Pine Editor Pine Script
//@version=5
strategy('Supertrend Strategy - PineConnector', overlay=true)
LicenseID = 0 // Replace 0 with your PineConnector License ID before creating an alert.
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))

The value after LicenseID = must be your actual numeric License ID before you create an alert. If it still shows 0, replace that value with the ID from your PineConnector Portal. Leave the variable name LicenseID unchanged.

  • Symbol: syminfo.ticker sends the ticker of the chart used for the alert. If your broker uses a different name, follow the symbol-mapping example before continuing.
  • Risk Value: the default is 1; choose the value appropriate to your EA’s Volume Type and demo test.
  • ATR Length and Factor: these control SuperTrend’s calculation. The published defaults are 10 and 3. Changing them changes when the script signals.

Select Save, give the script a recognisable name, then Add to chart.

The script draws SuperTrend lines and blue PineConnector Buy/Sell labels. The strategy also appears in Strategy Tester, which displays simulated historical results for the selected symbol, timeframe and data feed.

Annotated SuperTrend chart showing the chart symbol and timeframe, PineConnector markers, and the Strategy Tester below Enlarge
Published orientation example from 2024. Strategy Tester results are simulated and are not MetaTrader account results.
Published orientation example from 2024. Strategy Tester results are simulated and are not MetaTrader account results.Open original
Annotated SuperTrend chart showing the chart symbol and timeframe, PineConnector markers, and the Strategy Tester below

Beside the script’s name, use the eye to show/hide it, Settings to change inputs, the source-code control to edit it, and the bin to remove it from the chart.

SuperTrend script toolbar with visibility, settings, source-code, delete and more controls Enlarge
SuperTrend script toolbar with visibility, settings, source-code, delete and more controlsOpen original
SuperTrend script toolbar with visibility, settings, source-code, delete and more controls

If you are comparing markers with strategy fills, remember that signal calculation and simulated fill timing can differ. See the strategy timing explanation.

The published walkthrough suggests a 1-minute chart for observing a test sooner than a daily chart: select that interval before creating the alert. A shorter interval does not guarantee an immediate SuperTrend direction change.

On the symbol and timeframe you intend to test, select Create alert and configure:

Field Choose
Condition Your saved SuperTrend strategy
Event type alert() function calls only
Webhook URL The PineConnector URL below
Alert name A name that identifies the script, symbol and timeframe

Enable Webhook URL in the alert’s notification settings.

Choose Create. This script supplies the buy and sell messages, so one alert can listen to both directions. Do not select Order fills and alert() function calls for this setup: that adds a separate event source.

Wait for a new real-time direction change. Adding the script does not send every historical signal.

  1. TradingView Alerts log: open the triggered alert and inspect its message. Confirm the License ID, buy/sell direction, symbol and risk value.
  2. PineConnector Signals log: find the corresponding received message and check its processing status.
  3. MetaTrader: check the account, symbol, order direction and volume. Read the Experts output for how the EA handled the message.
  4. Opposite signal: with the stated reversal setup, verify the close-and-open behaviour on demo. Confirm there is no unexpected duplicate or remaining opposite position.

If TradingView stops the alert for triggering too often, check its status and the regular-alert limit of 15 triggers in three minutes before restarting it.

What you see Where to look next
Chart marker, but no alert-log entry Check the alert is running on the intended saved script and event type.
TradingView fired, but PineConnector has no message Check the webhook and License ID; follow Missing signals.
PineConnector received it, but the trade is wrong or absent Read the full processing/Experts error and use Errors.
More than one trade per event Check duplicate alerts and EA/connection setup before another test.

Published SuperTrend setup walkthrough

The original walkthrough may show an older interface. Use the written instructions and current settings for your setup.Watch on YouTube
Written summary

Create the strategy, replace its License ID, choose the appropriate EA settings, create an alert for alert() calls, and confirm the message in TradingView, PineConnector and MetaTrader.

Use Add alerts to your script to understand the code or build dynamic messages. Review Best Practices & Tips before expanding to more symbols or accounts.

Browse Strategy examples for the other existing walkthrough, or Learn PineConnector for version conversion and alert tools.