AlphaTrend Strategy

AlphaTrend Strategy

AlphaTrend Strategy

Ready to streamline your trading process and increase efficiency?

Try PineConnector — Free →

We adapted a popular PineScript on TradingView, created by KivancOzbilgic, to be compatible with PineConnector. The strategy can be used to trade forex, stocks, futures, crypto and other instruments.

We recommend that paper trading should be done first, before running on your live trading accounts. With this script, an alert will be automatically trigger and will execute a trade on your MT4/5 terminal when your terminal is connected to our server – ideal if you are day trading or swing trading.

Implementation of the strategy

1. Create a new script

At the bottom of your TradingView tab, click "Pine Editor".


At the bottom panel, click "Open" and then click "New blank indicator".


You will see the default code shown in the attached image:


2. Attach the code

// This source code is subject to the terms of the Mozilla Public License 2.0 at
// author © KivancOzbilgic
// developer © KivancOzbilgic

indicator('PineConnector x AlphaTrend', shorttitle='PineConnector x AlphaTrend', overlay=true, format=format.price, precision=2)

coeff = input.float(1, 'Multiplier', step=0.1)
AP = input(14, 'Common Period')
ATR = ta.sma(, AP)
src = input(close)
showsignalsk = input(title='Show Signals?', defval=true)
novolumedata = input(title='Change calculation (no volume data)?', defval=false)
upT = low - ATR * coeff
downT = high + ATR * coeff
AlphaTrend = 0.0
AlphaTrend := (novolumedata ? ta.rsi(src, 14) >= 50 : ta.mfi(hlc3, 14) >= 50) ? upT < nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT : downT > nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : downT

color1 = AlphaTrend > AlphaTrend[2] ? #00E60F : AlphaTrend < AlphaTrend[2] ? #80000B : AlphaTrend[1] > AlphaTrend[3] ? #00E60F : #80000B
k1 = plot(AlphaTrend,, 0), linewidth=3)
k2 = plot(AlphaTrend[2],, 0), linewidth=3)

fill(k1, k2, color=color1)

alertcondition(ta.cross(close, AlphaTrend), title='Cross Alert', message='Price - AlphaTrend Crossing!')
alertcondition(ta.crossover(low, AlphaTrend), title='CrossOver Alarm', message='BUY SIGNAL!')
alertcondition(ta.crossunder(high, AlphaTrend), title='CrossUnder Alarm', message='SELL SIGNAL!')

alertcondition(ta.cross(close[1], AlphaTrend[1]), title='Cross Alert After Bar Close', message='Price - AlphaTrend Crossing!')
alertcondition(ta.crossover(low[1], AlphaTrend[1]), title='CrossOver Alarm After Bar Close', message='BUY SIGNAL!')
alertcondition(ta.crossunder(high[1], AlphaTrend[1]), title='CrossUnder Alarm After Bar Close', message='SELL SIGNAL!')

buySignalk = ta.crossover(AlphaTrend, AlphaTrend[2])
sellSignalk = ta.crossunder(AlphaTrend, AlphaTrend[2])

K1 = ta.barssince(buySignalk)
K2 = ta.barssince(sellSignalk)
O1 = ta.barssince(buySignalk[1])
O2 = ta.barssince(sellSignalk[1])

plotshape(buySignalk and showsignalsk and O1 > K2 and AlphaTrend[2] * 0.9999, style=shape.labelup, location=location.belowbar,, 0), size=size.large, text='PineConnector \n Buy',, 0))       //plotting up arrow when buy/long conditions met 
plotshape(sellSignalk and showsignalsk and O2 > K1 and AlphaTrend[2] * 1.0001, style=shape.labeldown, location=location.abovebar,, 0), size=size.large, text='PineConnector \n Sell',, 0))   //plotting down arrow when sell/short conditions met

if buySignalk and showsignalsk and O1 > K2 ? AlphaTrend[2] * 0.9999 : na
    alert('changetoyourLICENSEID,buy,' +syminfo.ticker+ ',risk=1', alert.freq_once_per_bar_close)

if sellSignalk and showsignalsk and O2 > K1 ? AlphaTrend[2] * 1.0001 : na
    alert('changetoyourLICENSEID,sell,' +syminfo.ticker+ ',risk=1', alert.freq_once_per_bar_close)

3. Add the alert code

The alert code added should be the following:

Update the License ID Instead of the License ID 60123456789, input your PineConnector License ID.
if buySignalk and showsignalsk and O1 > K2 ? AlphaTrend[2] * 0.9999 : na
    alert('60123456789,buy,' +syminfo.ticker+ ',risk=1', alert.freq_once_per_bar_close)

if sellSignalk and showsignalsk and O2 > K1 ? AlphaTrend[2] * 1.0001 : na
    alert('60123456789,sell,' +syminfo.ticker+ ',risk=1', alert.freq_once_per_bar_close)

4. Save the code

5. Add Indicator to Chart

6. Create alerts

Syntax Builder2Syntax Builder2