My code is not showing any errors, but when I tried to start it, is not giving any entries, besides that, I want to add a couple of extra filters:
- RSI >50 (when going long)
- SlowEMA > SMA (when going long)
- Close > SlowEMA (when going long)
any suggestions?
FastEMA = ema(close,9) // EMA Fast 9 periods
plot(FastEMA,color=color.fuchsia)
SlowEMA = ema(close,26) // EMA Slow 26 periods
plot(SlowEMA,color=color.blue)
plot(sma(close,200),color=color.gray) // SMA 200 periods
rsi = rsi(close, 14) // Relative strength index
// Donchian Channel
length = input(20, minval=1)
lower = lowest(length)
upper = highest(length)
basis = avg(upper, lower)
u = plot(upper, "Upper", color=#FF9400)
l = plot(lower, "Lower", color=#FF9400)
// Specify crossover conditions
longCondition = crossover(FastEMA, SlowEMA)
shortCondition = crossunder(FastEMA, SlowEMA)
// Execution
if (longCondition)
strategy.entry("long", strategy.long, 100)
You must add a function to exit the position as well, such as strategy.order, stragegy.close or strategy.exit.
Just as an example, if you would exit 5 bars after entering the trade, you could go with