Exit as per Moving average Values

13 Views Asked by At

I have written the code below. its very basic.

I want the exit values (in live and backtesting) as per the moving average value on that particular bar.

//@version=4
strategy("My Strategy", overlay=true)

Define your indicators
rsi = rsi(close, 14)
ma20 = sma(close, 20)

Define your conditions
enterCondition = crossover(rsi, 60)
exitCondition = close <= ma20

Plot your indicators for visual confirmation
plot(rsi, "RSI", color=color.blue)
hline(60, "Entry Level", color=color.green)
plot(ma20, "MA 20", color=color.red)

Execute your strategy
strategy.entry("Buy", strategy.long, when=enterCondition)
strategy.close("Buy", when=exitCondition)
1

There are 1 best solutions below

0
Devanshu Tyagi On

to implement an exit strategy based on moving average,we typically compare the current price crosses below the moving average,it might signal a potential exist