英文:
Don't show second crossover until price move 1% away from 1st crossover
问题
Crossover signal shows everytime when condition is true. I want it show less frequent. For example, second crossover signal only appears when price moves 1% away from first crossover, then 3rd crossover only appears when price moves 1% away from second crossover...
ema200 = ta.ema(close, 200)
uptrend = ema50 > ema200
downtrend = ema200 > ema50
plot(ema50, color = uptrend ? color.green : downtrend ? color.red : na)
plot(ema200, color = uptrend ? color.green : downtrend ? color.red : na)
long = ta.crossover(close, ema50)
plotchar(uptrend ? long : na, "Long", "▲", location.belowbar, color = color.green, text = "Long", size = size.tiny)
Please help
Thanks in advance.
英文:
Crossover signal shows everytime when condition is true. I want it show less frequent. For example, second crossover signal only appears when price moves 1% away from first crossover, then 3rd crossover only appears when price moves 1% away from second crossover...
ema50 = ta.ema(close,50)
ema200 = ta.ema(close,200)
uptrend = ema50>ema200
downtrend = ema200>ema50
plot(ema50, color = uptrend?color.green:downtrend?color.red:na)
plot(ema200, color = uptrend?color.green:downtrend?color.red:na)
long = ta.crossover(close, ema50)
plotchar(uptrend?long:na, "Long", "▲", location.belowbar, color = color.green, text = "Long",size = size.tiny)
Please help
Thanks in advance.
答案1
得分: 0
你应该设置一个变量,用于存储最后一个信号的收盘价,并添加一个条件来检查是否与该价值相差1%,如下所示:
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
uptrend = ema50 > ema200
downtrend = ema200 > ema50
plot(ema50, color=uptrend ? color.green : downtrend ? color.red : na)
plot(ema200, color=uptrend ? color.green : downtrend ? color.red : na)
crossover_threshold = 0.01
var last_crossover_price = na
long = ta.crossover(close, ema50)
if long
if na(last_crossover_price)
plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long", size = size.tiny)
last_crossover_price := close
else if abs(close - last_crossover_price) / last_crossover_price >= crossover_threshold
plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long", size = size.tiny)
last_crossover_price := close
plotchar(uptrend ? long : na, "Long", "▲", location.belowbar, color = color.green, text = "Long", size = size.tiny)
你可以为空头信号做相同的操作。
英文:
You should set a variable with the close price of you last signal and add a condition to check if it's 1% away from it, like this:
ema50 = ta.ema(close,50)
ema200 = ta.ema(close,200)
uptrend = ema50>ema200
downtrend = ema200>ema50
plot(ema50, color = uptrend?color.green:downtrend?color.red:na)
plot(ema200, color = uptrend?color.green:downtrend?color.red:na)
crossover_threshold = 0.01
var last_crossover_price = na
long = ta.crossover(close, ema50)
if long
if na(last_crossover_price)
plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long",size = size.tiny)
last_crossover_price := close
else if abs(close - last_crossover_price) / last_crossover_price >= crossover_threshold
plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long",size = size.tiny)
last_crossover_price := close
plotchar(uptrend?long:na, "Long", "▲", location.belowbar, color = color.green, text = "Long",size = size.tiny)
You can do the same for the the short sigal.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论