This strategy combines a triple exponential moving average system with a Stochastic RSI oscillator to identify trend-following entry opportunities directly on the price chart.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
96 lines of Pine Script v5 from 5212 EMA Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
5212 EMA Strategy.pine
//@version=5
strategy(title='5212 EMA Strategy', shorttitle='5212 EMA', overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=10, calc_on_every_tick=false)
//**Backtest Date sof
useStartPeriodTime = input.bool(true , 'Start Date & Time' , group='Date Range' , inline='Start Period')
startPeriodTime = input.time(timestamp('16 Apr 2021') , '' , group='Date Range' , inline='Start Period')
useEndPeriodTime = input.bool(false , 'End Date & Time' , group='Date Range' , inline='End Period')
endPeriodTime = input.time(timestamp('31 Dec 2222') , '' , group='Date Range' , inline='End Period')
enableHighlight = input.bool(false , 'Highlight' , group='Date Range' , inline='Highlight')
highlightType = input.string('Anchors' , '' , group='Date Range' , inline='Highlight' , options=['Anchors', 'Background'])
highlightColor = input.color(color.white , '' , group='Date Range' , inline='Highlight')
start = useStartPeriodTime ? startPeriodTime >= time : false
end = useEndPeriodTime ? endPeriodTime <= time : false
calcPeriod = not start and not end
var line startAnchor = line.new(na, na, na, na, xloc.bar_time, extend.both, highlightColor, width=2)
var line endAnchor = line.new(na, na, na, na, xloc.bar_time, extend.both, highlightColor, width=2)
useBgcolor = false
if enableHighlight
if highlightType == 'Anchors'
if useStartPeriodTime
line.set_xy1(startAnchor, startPeriodTime, low)
line.set_xy2(startAnchor, startPeriodTime, high)
if useEndPeriodTime
line.set_xy1(endAnchor, calcPeriod ? time : line.get_x1(endAnchor), low)
line.set_xy2(endAnchor, calcPeriod ? time : line.get_x1(endAnchor), high)
if highlightType == 'Background'
useBgcolor := true
useBgcolor
bgcolor(useBgcolor and calcPeriod ? color.new(highlightColor,90) : na, editable=false)
//**Backtest Date eof
src =input(close , 'Source' , group='Support')
showEMA = input(true , 'Show EMA' , group='Support')
//**Stochastic RSI sof
smoothK = input.int(6 , "K" , group='Stochastic RSI' , minval=1)
smoothD = input.int(6 , "D" , group='Stochastic RSI' , minval=1)
lengthRSI = input.int(28 , "RSI Length" , group='Stochastic RSI' , minval=1)
lengthStoch = input.int(28 , "Stoch Length" , group='Stochastic RSI' , minval=1)
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
//**STochastic RSI eof
//** EMA sof
emain01 = input.int(50 , "EMAma Girang" , group='Moving Average Exponential' , minval=1)
emain02 = input.int(100 , "EMAma Muda" , group='Moving Average Exponential' , minval=1)
emain03 = input.int(200 , "EMAma Tua" , group='Moving Average Exponential' , minval=1)
ema01 = ta.ema(src, emain01)
ema02 = ta.ema(src, emain02)
ema03 = ta.ema(src, emain03)
plot(showEMA ? ema01 : na, 'EMAma Girang' , color = color.new(color.orange, 0))
plot(showEMA ? ema02 : na, 'EMAma Muda' , color = color.new(color.blue, 0))
plot(showEMA ? ema03 : na, 'EMAma Tua' , color = color.new(color.red, 0))
//** EMA eof
//**Condition sof
emaLong = ema01 > ema02 and ema02 > ema03 and low > ema03
emaShort = ema01 < ema02 and ema02 < ema03 and high < ema03
longCond = ta.crossover(k,d) and k <= 23 and emaLong
shortCond = ta.crossunder(k,d) and k >= 77 and emaShort
longClose = ta.crossunder(k,d) and k <= 77
shortClose = ta.crossover(k,d) and k >= 23
longCross = ta.crossover(ema01, ema02)
shortCross = ta.crossunder(ema01, ema02)
//**Condition eof
//**Strategy sof
if calcPeriod and longCond
strategy.entry('long', strategy.long, when=longCond, comment='EN Long')
strategy.close('long', when=shortClose, comment='EX Long')
strategy.close('long', when=shortCross, comment='MD Short')
if calcPeriod and shortCond
strategy.entry('short', strategy.short, when=shortCond, comment='EN Short')
strategy.close('short', when=longClose, comment='EX Short')
strategy.close('short', when=longCross, comment='MD Long')
if calcPeriod == false and ta.crossover(ema01, ema02) or ta.crossunder(ema01, ema02)
strategy.cancel('long')
strategy.cancel('short')
//**Strategy eof
//**Label sof
entryText = str.tostring(strategy.position_avg_price, '##.###')
longText = 'Long Entry : ' + entryText
shortText = 'Short Entry : ' + entryText
noTrade = 'Sleeping Mode'
LongTrade = strategy.position_size > 0
ShortTrade = strategy.position_size < 0
Tekslabel = LongTrade ? longText : ShortTrade ? shortText : noTrade
xPosition = timenow + math.round(ta.change(time)*1)
yPosition = ta.highest(1)
labelColor = LongTrade ? color.new(color.aqua, 0) : ShortTrade ? color.new(color.red, 0) : color.new(color.gray, 0)
textColor = LongTrade ? color.new(color.black, 0) : ShortTrade ? color.new(color.white, 0) : color.new(color.white, 0)
lab_l = label.new(
xPosition, yPosition, Tekslabel,
color=labelColor,
textcolor=textColor,
style = label.style_label_left,
textalign=text.align_left,
xloc=xloc.bar_time, yloc = yloc.price)
label.delete(lab_l[1])
//**Strategy eof
Expand (116 lines)
Overview
5212 EMA Strategy plots 50, 100, and 200-period EMAs while computing smoothed Stochastic RSI values in the background. Traders can adjust the moving average lengths, oscillator smoothing parameters, and backtest date ranges with visual highlight options. Position sizing defaults to ten percent of equity per trade, and the script operates without an automated stop loss.
Triple Exponential Moving Average overlay (50, 100, 200 periods)
Integrated Stochastic RSI momentum filter
Configurable backtest date range with visual anchor lines
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Start Date & Time
bool
true
useStartPeriodTime
startPeriodTime
time
timestamp('16 Apr 2021')
startPeriodTime
End Date & Time
bool
false
useEndPeriodTime
endPeriodTime
time
timestamp('31 Dec 2222')
endPeriodTime
Highlight
bool
false
enableHighlight
highlightType
string
Anchors
highlightType
highlightColor
color
color.white
highlightColor
Source
source
close
src
Show EMA
bool
true
showEMA
K
int
6
smoothK
D
int
6
smoothD
RSI Length
int
28
lengthRSI
Show all 16 settings
Setting
Type
Default
Variable
Stoch Length
int
28
lengthStoch
EMAma Girang
int
50
emain01
EMAma Muda
int
100
emain02
EMAma Tua
int
200
emain03
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the
This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can
This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below
This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m
This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i
This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute