不要在价格移动离第一个十字交叉点1%之前显示第二个十字交叉点。

huangapple go评论90阅读模式
英文:

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...

  1. ema200 = ta.ema(close, 200)
  2. uptrend = ema50 > ema200
  3. downtrend = ema200 > ema50
  4. plot(ema50, color = uptrend ? color.green : downtrend ? color.red : na)
  5. plot(ema200, color = uptrend ? color.green : downtrend ? color.red : na)
  6. long = ta.crossover(close, ema50)
  7. plotchar(uptrend ? long : na, "Long", "▲", location.belowbar, color = color.green, text = "Long", size = size.tiny)

signal shows too many

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...

  1. ema50 = ta.ema(close,50)
  2. ema200 = ta.ema(close,200)
  3. uptrend = ema50>ema200
  4. downtrend = ema200>ema50
  5. plot(ema50, color = uptrend?color.green:downtrend?color.red:na)
  6. plot(ema200, color = uptrend?color.green:downtrend?color.red:na)
  7. long = ta.crossover(close, ema50)
  8. plotchar(uptrend?long:na, "Long", "▲", location.belowbar, color = color.green, text = "Long",size = size.tiny)

signal shows too many

Please help
Thanks in advance.

答案1

得分: 0

你应该设置一个变量,用于存储最后一个信号的收盘价,并添加一个条件来检查是否与该价值相差1%,如下所示:

  1. ema50 = ta.ema(close, 50)
  2. ema200 = ta.ema(close, 200)
  3. uptrend = ema50 > ema200
  4. downtrend = ema200 > ema50
  5. plot(ema50, color=uptrend ? color.green : downtrend ? color.red : na)
  6. plot(ema200, color=uptrend ? color.green : downtrend ? color.red : na)
  7. crossover_threshold = 0.01
  8. var last_crossover_price = na
  9. long = ta.crossover(close, ema50)
  10. if long
  11. if na(last_crossover_price)
  12. plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long", size = size.tiny)
  13. last_crossover_price := close
  14. else if abs(close - last_crossover_price) / last_crossover_price >= crossover_threshold
  15. plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long", size = size.tiny)
  16. last_crossover_price := close
  17. 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:

  1. ema50 = ta.ema(close,50)
  2. ema200 = ta.ema(close,200)
  3. uptrend = ema50>ema200
  4. downtrend = ema200>ema50
  5. plot(ema50, color = uptrend?color.green:downtrend?color.red:na)
  6. plot(ema200, color = uptrend?color.green:downtrend?color.red:na)
  7. crossover_threshold = 0.01
  8. var last_crossover_price = na
  9. long = ta.crossover(close, ema50)
  10. if long
  11. if na(last_crossover_price)
  12. plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long",size = size.tiny)
  13. last_crossover_price := close
  14. else if abs(close - last_crossover_price) / last_crossover_price >= crossover_threshold
  15. plotchar(true, "Long", "▲", location.belowbar, color = color.green, text = "Long",size = size.tiny)
  16. last_crossover_price := close
  17. 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.

huangapple
  • 本文由 发表于 2023年4月11日 12:01:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定