Pine script 基于3个值进行绘图

Pine script 基于3个值进行绘图,pine-script,Pine Script,我发现了一个脚本,并想调整它,使其在主图表上有警报和绘图,但我被困在如何做到这一点 我期待着绘制一个信号时,所有3条在直方图是浅颜色,然后再次当他们都切换到黑暗的信号 任何帮助或指导都将不胜感激 谢谢, ''' study(title="3 Linear Regression Curve", shorttitle="Triple LRC", overlay=false) src = close len1 = input(10) len2 = input(14) len3 = input(30)

我发现了一个脚本,并想调整它,使其在主图表上有警报和绘图,但我被困在如何做到这一点

我期待着绘制一个信号时,所有3条在直方图是浅颜色,然后再次当他们都切换到黑暗的信号

任何帮助或指导都将不胜感激

谢谢,

'''
study(title="3 Linear Regression Curve", shorttitle="Triple LRC", overlay=false)
src = close
len1 = input(10)
len2 = input(14)
len3 = input(30)
offset = 0
reg1 = linreg(src, len1, offset)
reg2 = linreg(src, len2, offset)
reg3 = linreg(src, len3, offset)

hist1 = 3
hist2 = 2
hist3 = 1

plot(hist1,style=histogram,color=reg1>reg1[1]?aqua:blue,transp=0,linewidth=3)
plot(hist2,style=histogram,color=reg2>reg2[1]?yellow:orange,transp=0,linewidth=3)
plot(hist3,style=histogram,color=reg3>reg3[1]?lime:green,transp=0,linewidth=3)
'''

在这种情况下,如果您使用
overlay=false
,最好使用另一个脚本,通过
plotshape()
函数查看可能的买卖信号

你应该小心你的买卖信号。当信号之一为
TRUE
时,您将收到每个条的警报。理想情况下,你希望有一个买入信号,然后是一个卖出信号

请查看以下脚本:

//@version=4
study(title="3 Linear Regression Curve Overlay", shorttitle="Triple LRC", overlay=true)
src = close
len1 = input(10)
len2 = input(14)
len3 = input(30)

var isLong = false      // Flag to see if you are already long
var isShort = false     // Flag to see if you are already short

offset = 0
reg1 = linreg(src, len1, offset)
reg2 = linreg(src, len2, offset)
reg3 = linreg(src, len3, offset)

hist1 = 3
hist2 = 2
hist3 = 1

buyCondition = not isLong and (reg1 > reg1[1]) and (reg2 > reg2[1]) and (reg3 > reg3[1])        // Go long only if you are not already long
sellCondition = not isShort and (reg1 <= reg1[1]) and (reg2 <= reg2[1]) and (reg3 <= reg3[1])   // Go short only if you are not already short

if (buyCondition)       // Set flags
    isLong := true
    isShort := false

if (sellCondition)      // Set flags
    isLong := false
    isShort := true
plotshape(series=buyCondition, text="BUY", style=shape.triangleup, color=color.green, location=location.belowbar, size=size.small)
plotshape(series=sellCondition, text="SELL", style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small)
/@version=4
研究(title=“3线性回归曲线叠加”,shorttitle=“三重LRC”,叠加=真)
src=关闭
len1=输入(10)
len2=输入(14)
len3=输入(30)
var isLong=false//标记以查看您是否已经很长
var isShort=false//标记以查看您是否已经做空
偏移量=0
reg1=linreg(src,len1,偏移量)
reg2=linreg(src,len2,offset)
reg3=linreg(src,len3,offset)
历史1=3
hist2=2
hist3=1
buyCondition=not isLong and(reg1>reg1[1])and(reg2>reg2[1])and(reg3>reg3[1])//仅当您还不长时才走长
sellCondition=not isShort and(reg1 reg3[1])//仅当您还没有做多时才做多
sellCondition=notisshort和(reg1 reg3[1]?color.lime:color.green,transp=0,linewidth=3)
请记住,您应该按照说明和手动设置警报


哇,这太棒了,我要花上一辈子的时间才能弄明白,我真的很感谢你的帮助和见解。一个重要的细节-与实际用例更相关:我建议你也使用TradingView
strategy()
作为策略进行回溯测试,并使用相应的条目和出口,或者在Excel、Matlab中自己模拟它,或者别的什么。原因如下:虽然它在图形上看起来很神奇,当然也有一些很好的捕捉,但你必须小心,这里的计算很可能在酒吧关门时触发一个标志,而不是在他们非常乞讨时,这可能会从根本上改变盈利能力。祝你好运很好的观点@GlaucoEsturilio。因此,我建议使用历史值,看看你的情况在一个酒吧前是否属实。
//@version=4
study(title="3 Linear Regression Curve", shorttitle="Triple LRC", overlay=false)
src = close
len1 = input(10)
len2 = input(14)
len3 = input(30)

var isLong = false
var isShort = false

offset = 0
reg1 = linreg(src, len1, offset)
reg2 = linreg(src, len2, offset)
reg3 = linreg(src, len3, offset)

hist1 = 3
hist2 = 2
hist3 = 1

buyCondition = not isLong and (reg1 > reg1[1]) and (reg2 > reg2[1]) and (reg3 > reg3[1])        // Go long only if you are not already long
sellCondition = not isShort and (reg1 <= reg1[1]) and (reg2 <= reg2[1]) and (reg3 <= reg3[1])   // Go short only if you are not already short

if (buyCondition)       // Set flags
    isLong := true
    isShort := false

if (sellCondition)      // Set flags
    isLong := false
    isShort := true

alertcondition(condition=buyCondition, title="Alert: All light colors", message="BUY")
alertcondition(condition=sellCondition, title="Alert: All dark colors", message="SELL")

plot(hist1, style=plot.style_histogram, color= reg1 > reg1[1] ? color.aqua:color.blue, transp=0,linewidth=3)
plot(hist2, style=plot.style_histogram, color= reg2 > reg2[1] ? color.yellow:color.orange, transp=0,linewidth=3)
plot(hist3, style=plot.style_histogram, color= reg3 > reg3[1] ? color.lime:color.green, transp=0,linewidth=3)