Strategy · Pine Script v5 · On the chart

5212 EMA Strategy

by hasnocool

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.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code96
Settings16inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Start Date & TimebooltrueuseStartPeriodTime
startPeriodTimetimetimestamp('16 Apr 2021')startPeriodTime
End Date & TimeboolfalseuseEndPeriodTime
endPeriodTimetimetimestamp('31 Dec 2222')endPeriodTime
HighlightboolfalseenableHighlight
highlightTypestringAnchorshighlightType
highlightColorcolorcolor.whitehighlightColor
Sourcesourceclosesrc
Show EMAbooltrueshowEMA
Kint6smoothK
Dint6smoothD
RSI Lengthint28lengthRSI
Show all 16 settings
SettingTypeDefaultVariable
Stoch Lengthint28lengthStoch
EMAma Girangint50emain01
EMAma Mudaint100emain02
EMAma Tuaint200emain03
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.

Similar Pine Scripts

330 stars

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

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

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

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

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

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

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

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

SMA RSI Strategy

by PythonForForex
64 stars

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

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI Strategy

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

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

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers