繁体   English   中英

松树脚本 - plot 三角形,如果在前 6 根蜡烛中条件为真 2 次

[英]pine script - plot triangle if condition is true 2 times in previous 6 candles

我正在尝试 plot 一个三角形,如果在前 6 个烛台内,至少有 2 次发生移动交叉。 我有以下脚本,但我不知道如何编写 if 语句。 非常感谢您的任何建议!

//@version=4
study(title="Crossover", overlay=true,resolution="")

first = ema(close, 5)
seconds = ema(close, 13)
third = sma(close,21)
fourth = sma(close,34)
fifth = sma(close, 55)
sixth = sma(close,89)


plot(first, title="EMA 5", color=color.red, linewidth=1, transp=0)
plot(seconds, title="Ema 13", color=color.aqua, linewidth=1, transp=0)
plot(third, title="SMA 21", color=color.orange, linewidth=2, transp=0)
plot(fourth, title="SMA 34", color=color.blue, linewidth=2, transp=0)
plot(fifth, title="SMA 55", color=color.black, linewidth=2, transp=0)
plot(sixth, title="SMA 89", color=color.purple, linewidth=2, transp=0)


long1 = (first > seconds) and crossover(first,third)
long2 = (first > third) and crossover(first, seconds)
long3 = (first > fourth) and (first > seconds) and (first > third) and cross(first,fourth)


// if long1 or long2 or long3 is true 2 times in the previous 6 six candles then plot it ("long")
xxxxxx


plotshape(series=long, title="L", style=shape.triangleup, location=location.belowbar, color=color.green, text="L", size=size.small)

使用从barssince开始的酒吧:

LENGTH = 6

count1 = barssince(long1 or long2 or long3)
count2 = count1[count1 + 1]

plotshape(count1 + count2 < LENGTH - 1, title="L", style=shape.triangleup, location=location.belowbar, color=color.green, text="L", size=size.small)

更新

实际上,我的解决方案有点过度设计,我会按照 Bjorn Mistiaen 的建议推荐sum

LENGTH = 6    

count = sum(long1 or long2 or long3 ? 1 : 0, LENGTH)

plotshape(count >= 2, title="L", style=shape.triangleup, location=location.belowbar, color=color.green, text="L", size=size.small)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM