//@version=5
strategy("Relative Strength Strategy (4h)", overlay=true,
initial_capital=1000000,
commission_type=strategy.commission.percent,
commission_value=0.075,
currency = "USD",
default_qty_type = strategy.percent_of_equity,
default_qty_value = 100)
// Variables
color col = na
sma_mid_term_length = input.int(35, minval=1, title="Mid-term SMA (periods)")
FromYear = input.int(defval = 2017, title = "From Year", minval = 2000)
FromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay = 1 //input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)
Months = input.int(defval = 12, title = "Months", minval = 1)
ToYear = FromYear + int(Months / 12)//input.int(defval = 9999, title = "To Year", minval = 2017)
ToMonth = (Months + FromMonth) % 12 //input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = 1 //input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
// yesterday = timenow - 16 * 60 * 60 * 1000
window() =>
time >= start and time <= finish ? true : false // create function "within window of time"
avg_price = (low + high + open + close) / 4
sma_mid_term = ta.sma(avg_price, sma_mid_term_length)
relative_strength = (avg_price - sma_mid_term) / sma_mid_term
rs = sma_mid_term + sma_mid_term * ta.ema(relative_strength, sma_mid_term_length)
rs_delta = (rs / rs[1] - 1)
dir = ta.change(rs_delta >= 0 ? 1 : 0)
if not na(rs) and window()
strategy.cancel_all()
if dir > 0
if strategy.position_size == 0
strategy.order(id="L", direction=strategy.long, limit=avg_price*0.993)
strategy.exit(id="L1", from_entry="L", stop=avg_price*0.95)
else if dir[1] > 0 and dir == 0
if strategy.position_size == 0
strategy.order(id="L", direction=strategy.long, limit=avg_price*1.03)
strategy.exit(id="L2", from_entry="L", stop=avg_price*0.95)
else if dir < 0
if strategy.position_size > 0
strategy.exit(id="L3", from_entry="L", limit=strategy.position_avg_price)
else if dir[1] < 0 and dir == 0
if strategy.position_size > 0
strategy.exit(id="L4", from_entry="L", stop=strategy.position_avg_price*0.95)
else if dir == 0
if strategy.position_size > 0
strategy.exit(id="L5", from_entry="L", stop=strategy.position_avg_price*0.95)
if time > finish
strategy.close_all()
col := color.gray
col := rs_delta > 0 ? color.green : col
col := rs_delta < 0 ? color.red : col
plot(rs, color=col, style=plot.style_linebr)
plot(avg_price, style=plot.style_linebr)
plot(sma_mid_term, color=#673AB7)
Overview
Relative Strength Strategy (4h) averages open, high, low and close, smooths that with a mid-term SMA and builds a relative strength line from the gap between price and the SMA. When the slope of that line turns positive it places a limit order slightly below price, with a stop below. Other direction states manage exits using limit or stop orders around the average entry. A date window limits trading, positions close when it ends, and the lines draw on the chart.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Mid-term SMA (periods)
int
35
sma_mid_term_length
From Year
int
2017
FromYear
From Month
int
1
FromMonth
Months
int
12
Months
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
Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish
Donald - AI Futures 5M 15M Timeframe is an overlay trading strategy designed for intraday futures trading. It utilizes rational quadratic kernel regression to construct dynamic momentum zones and smoothed price boundaries on the main price chart. The strategy
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
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