Getting Started

FAQ

SuperTrend Strategy

SuperTrend Strategy

💡
Educational Purposes The purpose of this page is to demonstrate how you can fully automate a trading strategy on TradingView using PineConnector. Please note that the focus is not on the profitability of the strategy, if any.

SuperTrend Strategy

image

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

💡
Before proceeding, please ensure:
  1. PineConnector EA running on your MetaTrader terminal, where you should see:
    1. Your license details printed on your chart on MT4/5
    2. image
    3. Trading Account Connected on your Licensing Dashboard
    4. image
  2. Close on Reverse EA setting set as “On — Hedging”.
  3. image

1. Create a new strategy script

At the bottom of your TradingView tab, click "Pine Editor" → “Open” → “New strategy”.

image

2. Configure Script

2.1. Apply SuperTrend Strategy Code

Remove the default code generated, and attach the following code:

image
//@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

image

Once you have updated your License ID, save the strategy script, and add it to chart.

3. Orientation

image

Once you have successfully added the SuperTrend strategy on your chart, you should be able to see the following:

3.1. Upper Section

  1. 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.
  2. SuperTrend Strategy indicated on the top left corner, primarily,
    1. image
    2. Click the eye icon to show/hide the script’s interface
    3. Click the { } to make edits to the code
    4. Click the bin icon to remove the script from your chart
  3. On the chart, you will be able to see the strategy entries (in blue arrows, such as PineConnector Buy and PineConnector Sell)
    1. 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

  1. 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.
    1. Yes, profitability of a strategy may (and likely) differ based on the data feed provider of your choice (try it!)
    2. image
    3. 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

💡
In this tutorial, we’ll demonstrate alert creation using the EURUSD 24H chart. However, we recommend using the 1-minute chart for quicker testing, as it triggers sooner.

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.

image

4.2. Notifications Tab

Now, click on the Notifications tab, enable Webhook URL and add the following URL:

https://webhook.pineconnector.com 
image

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.

💡
New code? New alert. Changes to your code won’t automatically update existing alerts—they’ll continue using the original code saved at the time of creation.

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.

image
💡
Sky’s not the limit — 15 Is A single alert can trigger up to 15 times within a 3-minute window. If this limit is exceeded, the alerts will be automatically paused.

5.2. Confirmation on Signal Log

The corresponding alert will result in a new entry in your PineConnector Portal, under Signal Logs.

image

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.

image
💡
Monitoring for Success We recommend regularly checking the “Experts” tab to understand how the EA processes your alert messages, particularly when testing new syntax or adjusting EA settings.
image

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.

Always remember, if you have feedback, questions, or stuck, please feel free to chat with us! Chat with PineConnector Support →

💡
Maximize your Trading Performance: Use Our Broker of Choice To ensure optimal trading performance, we recommend using the same broker that we use for PineConnector testing. In addition, you can trigger your alerts based on the broker's data source available on TradingView, leading to better trading performance. Minimize errors, maximize your trading potential, and ensure the best possible experience with our platform.

Broker of Choice →