首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当特定交叉在x条内发生x次时的绘图信号

当特定交叉在x条内发生x次时的绘图信号
EN

Stack Overflow用户
提问于 2022-10-15 17:09:26
回答 1查看 79关注 0票数 0

我试图绘制一个购买信号,每次我的RSI超卖水平交叉发生至少3次期间内,最多30条。

我做了很多研究,但我是个新手。我尝试了一些有价值的密码,但是我没有找到正确的解决方法。

这是我的松木脚本,我的RSI超买和超卖水平的地块,它运行良好,没有问题:

代码语言:javascript
复制
RSIPeriod = input(13, "RSI Period")
BuyAlertLevel = input(-34, "RSI Buy Alert")
SellAlertLevel = input(34, "RSI Sell Alert")
RSIHistoModify = input(1.618, "RSI Fib Factor")

xPrice2 = close[1]
RSIMain = (ta.rsi(xPrice2, RSIPeriod) - 50) * RSIHistoModify

Buysignal = ta.crossunder(RSIMain, BuyAlertLevel)
Sellsignal = ta.crossover(RSIMain, SellAlertLevel)

show_rsi_signals = input(true, "RSI Signals")

plotchar(show_rsi_signals ? Buysignal: na, title="RSI Buy", char="•", location=location.belowbar, size=size.normal, color=color.rgb(255, 255, 255, 85))    
plotchar(show_rsi_signals ? Sellsignal: na, title="RSI Sell", char="•", location=location.abovebar, size=size.normal, color=color.rgb(255, 255, 255, 85))

最后,我用ta.valuewhen尝试了一些方法来检查在30小节中交叉是否至少发生了3次,但是它没有起作用:

代码语言:javascript
复制
rsibuy1 = ta.valuewhen(Buysignal, close, 3) <= 30
label.new(rsibuy1 ? bar_index:na, low, text='B', color=color.rgb(255, 255, 255, 100), style=label.style_label_up, textcolor=color.rgb(0, 194, 120, 80), size=size.small)

图表上的示例

我的RSI超买和超卖交叉地块是没有问题的。我只需要了解如何检查x数量的交叉在x数量的条状,以绘制它与另一个购买信号。

我正在使用松树脚本v5。

有人能帮忙吗?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-16 08:03:26

我使用for循环来查找真条件,在这里可以看到,每当我发现交叉count为true时,都会增加Buysignal变量。

以类似的方式,您可以在最后一个number_of_bar_to_lookfor条中使用for循环来销售/交叉下信号。

最后的信号是bgcolor() bgcolor(n_rsi_cross_found and not n_rsi_cross_found[1]?color.green:na,title='n number of cross found')的希望,这是有帮助的。

代码语言:javascript
复制
//@version=5
indicator("My script")
RSIPeriod = input(13, "RSI Period")
BuyAlertLevel = input(-34, "RSI Buy Alert")
SellAlertLevel = input(34, "RSI Sell Alert")
RSIHistoModify = input(1.618, "RSI Fib Factor")

xPrice2 = close[1]
RSIMain = (ta.rsi(xPrice2, RSIPeriod) - 50) * RSIHistoModify
plot(RSIMain)
Buysignal = ta.crossunder(RSIMain, BuyAlertLevel)
Sellsignal = ta.crossover(RSIMain, SellAlertLevel)

number_of_bar_to_lookfor=input.int(30,'Input Number of bars you want to look for',group='Setting for the Logic')
number_of_cross_happened=input.int(3,'Input Number of cross to happen',group='Setting for the Logic')

count=0
for i=0 to number_of_bar_to_lookfor
    if Buysignal[i]
        count+=1

n_rsi_cross_found=count>=number_of_cross_happened
bgcolor(n_rsi_cross_found and not n_rsi_cross_found[1]?color.green:na,title='n number of cross found')

show_rsi_signals = input(true, "RSI Signals")

plotchar(show_rsi_signals and Buysignal?RSIMain: na, title="RSI Buy", char="•", location=location.absolute, size=size.normal, color=color.rgb(255, 255, 255, 85))    
plotchar(show_rsi_signals and Sellsignal?RSIMain: na, title="RSI Sell", char="•", location=location.absolute, size=size.normal, color=color.rgb(255, 255, 255, 85))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74081484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档