如何在 pinescript 的安全功能(多 TF 指标)中使用输入?
How to use an input in a security function (Multi TF indicator) on pinescript?
我试图修改 Tradingview
上已经可用的指标。
想法是将 WaveTrends
转换为 "line" 指标,当满足超卖或超买条件时会改变颜色。这些指标是另一个时间范围内的波浪趋势。
我有两个问题,我想使用一个输入函数来更改时间范围,而不必通过更改代码来完成。
第二期,图片上可以看到4行
- 中期 TF 短路情况
- longTF空头条件
- 中期 TF 多头条件
- longTF 长条件。
我通过创建 2 条长线和 2 条短线来绕过我的困难,但我想将它们组合成 3 种不同颜色的 2 条线:绿色表示超卖状态,红色表示超买状态,最后是灰色.
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)
我试图修改 Tradingview
上已经可用的指标。
想法是将 WaveTrends
转换为 "line" 指标,当满足超卖或超买条件时会改变颜色。这些指标是另一个时间范围内的波浪趋势。
我有两个问题,我想使用一个输入函数来更改时间范围,而不必通过更改代码来完成。
第二期,图片上可以看到4行
- 中期 TF 短路情况
- longTF空头条件
- 中期 TF 多头条件
- longTF 长条件。
我通过创建 2 条长线和 2 条短线来绕过我的困难,但我想将它们组合成 3 种不同颜色的 2 条线:绿色表示超卖状态,红色表示超买状态,最后是灰色.
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)