-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrvi.strategy
32 lines (24 loc) · 899 Bytes
/
rvi.strategy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// @version=4
strategy("RVI Strategy", shorttitle="RVI-S", overlay=true)
// User-defined input parameters
length = input(10, title="Length", minval=1)
signalLength = input(4, title="Signal Length", minval=1)
// RVI calculation
numerator = close - open
denominator = high - low
numeratorSMA = sma(numerator, length)
denominatorSMA = sma(denominator, length)
rvi = numeratorSMA / denominatorSMA
// Signal line calculation
signalLine = sma(rvi, signalLength)
// Trading strategy
longCondition = crossover(rvi, signalLine)
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = crossunder(rvi, signalLine)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Plotting the RVI and its signal line
plot(rvi, title="RVI", color=color.blue, linewidth=2)
plot(signalLine, title="Signal Line", color=color.red, linewidth=2)
hline(0, "Zero Line", color=color.gray)