0bps

Strategy vault / Trend following

EMA200 and Stochastic RSI Strategy

EMA200 and Stochastic RSI Strategy This strategy is a combination of the Exponential Moving Average (EMA) and the Stochastic Relative Strength Index (RSI). It is designed to identify long and short trading…

Author
ChaoZhang
Complexity
Starter · 50 lines
Parameters
4
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

EMA200 and Stochastic RSI Strategy

This strategy is a combination of the Exponential Moving Average (EMA) and the Stochastic Relative Strength Index (RSI). It is designed to identify long and short trading opportunities based on the movement of the price above or below the EMA200 and the Stochastic RSI values.

How the strategy works

The strategy uses the following conditions to generate entry signals:

Long entry: The price is above the EMA200. The Stochastic RSI is below 20 and has crossed above the RSI. The current candle is a higher high candle. The current candle's body is at least 5% larger than the previous candle's body. Short entry: The price is below the EMA200. The Stochastic RSI is above 80 and has crossed below the RSI. The current candle is a lower low candle. The current candle's body is at least 5% smaller than the previous candle's body. Benefits of the strategy

The strategy has a number of potential benefits, including:

It is based on two well-established technical indicators. The EMA and the Stochastic RSI are both widely used by traders and have a long history of success. It is relatively easy to understand and implement. The strategy has a limited number of parameters, making it easy for traders of all experience levels to understand and use. It is flexible and can be used in a variety of market conditions. The strategy can be used to trade both long and short positions, and it can be used in both trending and ranging markets. Risks of the strategy

As with any trading strategy, there are also some potential risks associated with using the EMA200 and Stochastic RSI strategy, including:

The strategy is based on historical data. There is no guarantee that the strategy will be profitable in the future. The strategy can be susceptible to whipsaw. This is when the price of an asset moves rapidly in both directions, which can lead to losses. The strategy can be volatile. This means that there is a risk of large losses. Conclusion

The EMA200 and Stochastic RSI strategy is a relatively simple and effective trading strategy that can be used by traders of all experience levels. However, it is important to remember that no trading strategy is guaranteed to be profitable, and traders should always use caution when using any trading strategy.

Parameters

NameDefaultWhat it controls
v_input_12(?User-defined parameter: ATR multiple
v_input_float_11.5Profit and Loss Ratio
v_input_int_120Upper and lower shadow ratio(%)
v_input_float_20.5Key candlestick price change(%)

Source Pine Script

/*backtest
start: 2022-08-30 00:00:00
end: 2023-09-05 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © eaglezou1006

//@version=5
//strategy("70000%", overlay = true, initial_capital = 100, commission_value = 0.04, commission_type =strategy.commission.percent, pyramiding = 1, default_qty_value = 100, default_qty_type = strategy.cash, currency = currency.USDT)
//Stoch RSI
rsi1 = ta.rsi(close, 14)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, 14), 3)
d = ta.sma(k, 3)
//ema
ema200 = ta.ema(close, 200)
plot(ema200, color = color.white)
//atr
length = 14
smoothing = 'RMA'
m = input(2, 'ATRMultiplier', group = "User-defined parameters"")
src1 = high
src2 = low
pline = true

collong = color.teal
colshort = color.red

a = ta.rma(ta.tr(true), length) * m
x = ta.rma(ta.tr(true), length) * m + src1
x2 = src2 - ta.rma(ta.tr(true), length) * m
p1 = plot(x, title='ATR Short Stop Loss', color=color.new(colshort, 20), trackprice=pline ? true : false)
p2 = plot(x2, title='ATR Long Stop Loss', color=color.new(collong, 20), trackprice=pline ? true : false)

rewardRiskRatio = input.float(defval = 1.5, title = "Profit and Loss Ratio", minval = 1, maxval = 15, step = 0.1, group = "User-defined parameters")
highLowShadowRatio = input.int(defval = 20, title = "Upper and lower shadow ratio(%)", minval = 1, maxval = 100, step = 1, group = "User-defined parameters")
keyCandlestickChange = input.float(defval = 0.5, title = "Key candlestick price change(%)", minval = 0.1, maxval = 100, step = 0.1, group = "User-defined parameters")

longCondition = close > ema200 and (k < 20 and d < 20 and ta.crossover(k, d)) and high > high[1] and close[1] > open[1] and (close > open and (high-close) / (high-low) <= highLowShadowRatio / 100 and (close / open) - 1 >= keyCandlestickChange / 100)
shortCondition = close < ema200 and (k > 80 and d > 80 and ta.crossunder(k, d)) and low < low[1] and close[1] < open[1] and (close < open and math.abs(high-open) / math.abs(high-close) <= highLowShadowRatio / 100 and 1 - (close / open) >= keyCandlestickChange / 100 )
plotshape(longCondition, 'Buy', shape.labelup, location.belowbar, color=collong, size=size.small, offset=0)
plotshape(shortCondition, 'Sell', shape.labeldown, location.abovebar, color=colshort, size=size.small, offset=0)

if longCondition
    strategy.entry("Enter Long", strategy.long)
else if shortCondition
    strategy.entry("Enter Short", strategy.short)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-06. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/EMA200-and-Stochastic-RSI-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open