[英]How to use an input in a security function (Multi TF indicator) on pinescript?
我试图修改Tradingview
上已经可用的指标。
这个想法是将WaveTrends
转换为“线”指标,当满足超卖或超买条件时,该指标会改变颜色。 这些指标是来自另一个时间框架的波浪趋势。
我有两个问题,我想使用输入函数来更改时间范围,而不必通过更改代码来完成。
第二个问题,您可以在图像上看到 4 行
我通过创建 2 条长线和 2 条短线绕过了我的困难,但我想将它们组合成 2 条线,其中包含 3 种不同的颜色:绿色表示超卖状态,红色表示超买状态,最后是灰色介于两者之间。
study("WTcheckMTF", shorttitle="WTCMTF")
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
obLevel1 = input(60, "Over Bought Level 1")
obLevel2 = input(53, "Over Bought Level 2")
osLevel1 = input(-60, "Over Sold Level 1")
osLevel2 = input(-53, "Over Sold Level 2")
ap = hlc3
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)
wt1 = tci
wt2 = sma(wt1,4)
//Mid and longer TF defining
long = input("D", "Interval used for long TF", type = resolution)
mid = input("360", "Interval used for mid TF", type = resolution)
**MidWT = security(tickerid, "360",wt2)
LongWT = security(tickerid, "720", wt2)**
//treshold MT LT
LWTLT = input(-53, "OS Threshold L")
LWTMT = input(-53, "OS Threshold M")
SWTLT = input(53, "OB Threshold L")
SWTMT = input(53, "OB Threshold M")
L1=1
M1=2
L2=3
M2=4
// Color for MT LT indicators
**lcolor1 = LongWT <= LWTLT ? lime : gray
mcolor1 = MidWT <= LWTMT ? lime : gray
lcolor2 = LongWT >= SWTLT ? red : gray
mcolor2 = MidWT >= SWTMT ? red : gray**
// plot
plot(L1, style=line,color=lcolor1,linewidth=25)
plot(M1, style=line,color=mcolor1,linewidth=25)
plot(L2, style=line,color=lcolor2,linewidth=25)
plot(M2, style=line,color=mcolor2,linewidth=25)
启用您的输入呼叫以解决问题。 默认值应该是出现在下拉列表中的值,因此将"360"
更改为"240"
。
对于颜色,您的一行条件现在集中在一个语句中。 请注意如何将多个三元条件相互嵌入。 当您不习惯它们时,它们会更难以遵循,但非常方便。
记住在发布代码时在脚本的开头包含编译器指令,这样我们就可以知道您的脚本是为哪个版本的 Pine 编写的。
//@version=3
study("WTcheckMTF", shorttitle="WTCMTF")
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
obLevel1 = input(60, "Over Bought Level 1")
obLevel2 = input(53, "Over Bought Level 2")
osLevel1 = input(-60, "Over Sold Level 1")
osLevel2 = input(-53, "Over Sold Level 2")
ap = hlc3
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)
wt1 = tci
wt2 = sma(wt1,4)
//Mid and longer TF defining
long = input("D", "Interval used for long TF", type = resolution)
mid = input("240", "Interval used for mid TF", type = resolution)
MidWT = security(tickerid, mid, wt2)
LongWT = security(tickerid, long, wt2)
//treshold MT LT
LWTLT = input(-53, "OS Threshold L")
LWTMT = input(-53, "OS Threshold M")
SWTLT = input(53, "OB Threshold L")
SWTMT = input(53, "OB Threshold M")
L1=1
M1=2
L2=3
M2=4
// Color for MT LT indicators
lcolor = LongWT <= LWTLT ? lime : LongWT >= SWTLT ? red : gray
mcolor = MidWT <= LWTMT ? lime : MidWT >= SWTMT ? red : gray
// plot
plot(L1, "L1", lcolor, 25)
plot(M1, "M1", mcolor, 25)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.