I’ve changed the “religious” use of EMAs (“sponsored by” Alexander Elder) to “ordinary” MAs: this because since simple moving averages measure all the factor in addition egual each one, this involve a sort of “offset” in the graph, while EMAs give a major “importance” to the last value (last close itself, you’re already considering): therefore this calculation may be counterproductive.
Indeed the purpose was to improve the result of the previous code (https://sauciusfinance.altervista.org/2-emas-malverti-and-rsi-trading-system-on-tradingview/) simply using marginal changes, i.e. replacing in the code all the EMAs to simple SMAs. The first effect is to reduce the false enters given by a reactive indicator.
==> RESULTS ARE GOOD: almost all the system on Italian and major European shares have improved their perfomance of a 10-15%, with a minor number of operations.
OPTIMIZATION: use period for fast = long MA = 11 periods , stop to 7 periods (in original, while for EMAS the value was best at 5) and RSI “stable” at 14.
P.S. i’ve added only a graphical indication for MA-200 for those who want to risk less, using this indicator as “watershed” between bull and bear markets.
CODE
//@version= 4
// form the original idea of Enrico Malverti www.enricomalverti.com , trading system 2015
// https://sauciusfinance.altervista.org
strategy(title=”MAs & RSI strategy long only”, overlay = true, max_bars_back=500)
///FROM EMAS TO SIMPLE MA *
// NON AGGIUNTO SCHAFF INDICATOR, che serve per discriminare quali titoli scegliere dallo screener (segnale già aperto o il primo o, a parità,
//quello più alto) ==> Tolte le bande di Bollinger (che filtrano “poco”)
// INPUTS
emapf = input(14, title =”Ma periodo veloce”, minval=1, step = 1)
emapl = input(14, title =”Ma periodo lungo”, minval=1, step = 1)
emaps = input(7, title =”Ma periodi stop”, minval=1, step = 1)
rsi_period = input(14, title=”RSI period”, minval = 1, step = 1)
// CALCULATIONS
maf = sma(close, emapf)
mal = sma(close, emapl)
// rsi
myrsi = rsi(close, rsi_period)
//ema stop long ed ema stop short
//Ema7 messo da “massimo” a “chiusura” come target per posizioni short. Il limite è, in questo caso, sempre ema20 (più restringente – asimmetria)
// in questo t.s., lo short viene soltanto indicato come “rappresentazione grafica”, non agito
mass = sma(close, emaps)
masl = sma(low, emaps)
ma200=sma(close,200)
/// Entry
strategy.entry(“Long”, true, when = crossover(close,mal))
rsi1 = crossunder(myrsi,70)
rsi2 = myrsi > 75
// previously, 80
st_loss_long = crossunder(close,masl)// chiusura sotto EMA7
target_long= crossunder(close,maf) //* Chiusura sotto EMA14*
// exits. RSI*Long: Target if over bandamax, loss if under bandamin. Viceversa, for short
strategy.close(“Long”, when = rsi1, comment=”crossunder RSI”)
strategy.close(“Long”, when = rsi2, comment =”RSI MAX”)
strategy.close(“Long”, when = st_loss_long, comment = “Stop loss”)
strategy.close(“Long”, when = target_long, comment = “target_long” )
plot(masl, title=”ma stop long”, color=#363A45, linewidth= 1, style=plot.style_cross)
plot(maf, title=”MA FAST”, color=#FF0000, linewidth= 1)
plot(mal, title=”MA SLOW”, color=#0000FF, linewidth= 2)
plot(mass, title=”ma stop short”, color=#787B86,linewidth= 1, style=plot.style_cross)
plot(ma200, title=”ma200″, color=color.black, linewidth= 1)