本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Shivam_Mandrai
//@version=6
indicator("IU Mean Reversion System", overlay = true)
// ___________________________________________________ user Inputs ___________________________________________________ \\
mean_length = input.int(9, "Mean length = ")
atr_length = input.int(100, "ATR Length = ")
multi = input.float(3, "Multiplier")
// ___________________________________________________ indicators ____________________________________________________ \\
ema = ta.ema(close, 9)
mean = ta.rma(ema, 9)
atr = ta.atr(atr_length)
// ___________________________________________________ Condtions and calcualtions _____________________________________ \\
upper = mean + atr * multi
lower = mean - atr * multi
long = ta.crossover(close, lower)
short = ta.crossunder(close, upper)
long_exit = ta.crossover(high, mean)
short_exit = ta.crossunder(low, mean)
// ___________________________________________________ Entry and Exit logic ____________________________________________ \\
// ------------ presistance variables ---------- \\
var in_long = false
var in_short = false
// ------------ entry part ----------------------- \\
if long and in_long == false
in_long := true
if short and in_short == false
in_short := true
// ------------ exit part ----------------------- \\
if long_exit
in_long := false
if short_exit
in_short := false
// ____________________________________________________ Entry Exit labesls ________________________________________________ \\
plotshape(long_exit and in_long[1], "Long", shape.labeldown, location = location.abovebar, color = color.gray, text = 'Long Exit', textcolor = color.white)
plotshape(short_exit and in_short[1], "Short", shape.labelup, location = location.belowbar, color = color.gray, text = 'Short Exit', textcolor = color.white)
plotshape(in_long and not in_long[1], "Long", shape.labelup, location = location.belowbar, color = color.green, text = 'Long Entry', textcolor = color.white)
plotshape(in_short and not in_short[1], "Short", shape.labeldown, location = location.abovebar, color = color.red, text = 'Short Entry', textcolor = color.white)
// ____________________________________________________ plotting and filling _______________________________________________ \\
plot(mean, color = color.lime)
upper_plot = plot(upper, color = color.gray)
lower_plot = plot(lower, color = color.gray)
fill(upper_plot, lower_plot, color= color.new(color.blue, 90))