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

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

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)

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

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)

signal shows too many

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.

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:

确定