Strategy · Pine Script v4 · On the chart

Triple EMA + Stochastic Long Strategy (D)

by krosenfeld7

This strategy plots three exponential moving averages on the price chart and opens long trades when those averages stack upward, price closes above the shortest average, and a smoothed stochastic RSI has K above D.

View on GitHub

GitHub stars5on the repository
Pine versionv4older, still runs
Lines of code73
Settings18inputs
LicenceApache-2.0
Last update3 years ago12 May 2023

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

73 lines of Pine Script v4 from Triple_EMA+Stochastic_RSI/Triple_EMA+Stochastic_RSI_Long_Strategy.txt, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

Triple_EMA+Stochastic_RSI_Long_Strategy.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © krosenfeld7

// This script is best on the daily timeframe
//@version=4
strategy("Triple EMA + Stochastic Long Strategy (D)", overlay = true, pyramiding = 0, 
         margin_long = 100, margin_short = 100, default_qty_type = strategy.percent_of_equity, 
         default_qty_value = 20, initial_capital = 2000, process_orders_on_close = true)

// Set the starting point for backtesting
start = input(title="Backtesting Start", type=input.time, defval=timestamp("1 Jan 2015"))
// Expiration time on orders
maxTimeOpen = input(title="Order Expiration", type=input.integer, defval=130, minval=1)
useAtr = input(title="Use ATR?", type=input.bool, defval=false)

// Algorithm / Strategy Goes here
// Set long / short variables to execute positions below
len1 = input(20, minval=1, title="Short EMA Length")
src1 = input(close, title="Short EMA Source")
out1 = ema(src1, len1)
plot(out1, title="Short EMA", color=color.blue, linewidth=3)
len2 = input(50, minval=1, title="Intermediate EMA Length")
src2 = input(close, title="Intermediate EMA Source")
out2 = ema(src2, len2)
plot(out2, title="Intermediate EMA", color=color.yellow, linewidth=3)
len3 = input(200, minval=1, title="Long EMA Length")
src3 = input(close, title="Long EMA Source")
out3 = ema(src3, len3)
plot(out3, title="Long EMA", color=color.white, linewidth=3)

// Stochastic RSI Section
smoothK = input(3, "Stochastic K", minval=1)
smoothD = input(3, "Stochastic D", minval=1)
src = input(close, title="RSI Source")
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)

// Computing Strategy
long = (barstate.isconfirmed and (k > d) and (out1 > out2) and (out2 > out3) and (close > out1) and ((open < close) and (close > close[1])) and (open > out1)) ? 1 : 0
short = (barstate.isconfirmed and (d > k) and ((out1 < out2) and (out2 < out3)) and (close < out1) and ((open > close) and (close < close[1])) and (open < out1)) ? 1 : 0

// Average True Range
length = input(title="ATR Length", defval=14, minval=1)
atrMultiplier = input(title="ATR Multiplier", type=input.float, defval=1, minval=0.1)
atr = atr(length)

longProfitPercent = input(title = "Profit %",
     type = input.float, minval = 0.0, step = 0.1, defval = 30) / 100
longLossPercent = input(title = "Loss %",
     type = input.float, minval = 0.0, step = 0.1, defval = 100) / 100

// Calculating exact prices for stop loss and exit prices
longExitPercentPrice = strategy.position_avg_price * (1 + longProfitPercent)
longStopPercentPrice = strategy.position_avg_price * (1 - longLossPercent)

// Profit & Loss via ATR
longExitPrice = useAtr ? strategy.position_avg_price + atr * atrMultiplier : longExitPercentPrice
longStopPrice = useAtr ? strategy.position_avg_price - atr * atrMultiplier : longStopPercentPrice

// Plotting profit / loss targets
plot(series = (strategy.position_size > 0) ? longExitPrice : na, color = color.green, style = plot.style_linebr, transp = 0, linewidth = 3, title = "Long Target")
plot(series = (strategy.position_size > 0) ? longStopPrice : na, color = color.red, style = plot.style_linebr, transp = 0, linewidth = 3, title = "Long Stop Loss")

// Submit entry orders
if time >= start
    strategy.entry(id = "Long", long = strategy.long, comment = "Long Open", when = long)

// Submit exit orders
strategy.exit(id = "Long", limit = longExitPrice, stop = longStopPrice, comment = "Long Close", when = strategy.position_size > 0)
strategy.close(id = "Long", comment = "Expired: >" + tostring(maxTimeOpen), when = (barssince(change(strategy.opentrades)) + 1) >= maxTimeOpen)

Overview

Triple EMA + Stochastic Long Strategy (D) also requires a rising bullish candle on a confirmed bar. Exits use a percentage target and stop, or an ATR distance when that option is on. Settings change EMA lengths, oscillator smoothing, the ATR multiplier, and the profit and loss percentages. The author notes the daily timeframe. A short condition is calculated, but the visible orders only open longs, and pyramiding is off.

Details

Published by

krosenfeld7 on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Backtesting Starttimetimestamp("1 Jan 2015")start
Order Expirationint130maxTimeOpen
Use ATR?boolfalseuseAtr
Short EMA Lengthint20len1
Short EMA Sourcesourceclosesrc1
Intermediate EMA Lengthint50len2
Intermediate EMA Sourcesourceclosesrc2
Long EMA Lengthint200len3
Long EMA Sourcesourceclosesrc3
Stochastic Kint3smoothK
Stochastic Dint3smoothD
RSI Sourcesourceclosesrc
Show all 18 settings
SettingTypeDefaultVariable
RSI Lengthint14lengthRSI
Stochastic Lengthint14lengthStoch
ATR Lengthint14length
ATR Multiplierfloat1atrMultiplier
Profit %float30longProfitPercent
Loss %float100longLossPercent
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

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

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

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