基于 3 个值绘制
Plotting based on 3 values
我找到了一个脚本,想对其进行调整以在主图表上显示警报和绘图,但我不知道如何操作。
我希望在直方图中的所有 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
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)
请记住,您应该按照 here and here 所述手动设置警报。
我找到了一个脚本,想对其进行调整以在主图表上显示警报和绘图,但我不知道如何操作。
我希望在直方图中的所有 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
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)
请记住,您应该按照 here and here 所述手动设置警报。