[英]Issue in converting this tradingview pinescript from v2 to v5
我想将我的脚本从 v2 策略转换为 v5 策略并添加买卖警报。 此脚本在 v2 中运行良好,我能够在屏幕上看到买入/卖出信号,但也希望在出现任何买入/卖出信号时弹出警报。
以下是我的脚本
//@version=2
strategy("testLearn", overlay=true, default_qty_value=1)
res = input(title=" SuperTrend", type=resolution, defval="720")
Factor=input(2, minval=1,maxval = 1)
Pd=input(10, minval=1,maxval = 1)
tp = input(5,title="Take Profit")
sl = input(2,title="Stop Loss")
Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
MUp=security(tickerid,res,hl2-(Factor*atr(Pd)))
MDn=security(tickerid,res,hl2+(Factor*atr(Pd)))
Mclose=security(tickerid,res,close)
TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
MTrendUp=Mclose[1]>MTrendUp[1]? max(MUp,MTrendUp[1]) : MUp
MTrendDown=Mclose[1]<MTrendDown[1]? min(MDn,MTrendDown[1]) : MDn
Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
MTrend = Mclose > MTrendDown[1] ? 1: Mclose< MTrendUp[1]? -1: nz(MTrend[1],1)
MTsl = MTrend==1? MTrendUp: MTrendDown
linecolor = Trend == 1 ? green: red
plot(Tsl, color = linecolor , style = line , linewidth = 1,title = "SuperTrend")
Mlinecolor = MTrend == 1 ? blue : red
//plot(MTsl, color = Mlinecolor , style = line , linewidth = 4,title = "Main SuperTrend")
plotshape(cross(close,Tsl) and close>Tsl , "Up Arrow", shape.triangleup,location.belowbar,lime,0,0, text="==Buy==")
plotshape(cross(Tsl,close) and close<Tsl , "Down Arrow", shape.triangledown , location.abovebar, red,0,0, text="==Sell==")
up = Trend == 1 and Trend[1] == -1 and MTrend == 1
down = Trend == -1 and Trend[1] == 1 and MTrend == -1
alertcondition(condition=cross(close,Tsl) and close>Tsl, message="Buy::{{ticker}}:{{close}}")
alertcondition(condition=cross(Tsl,close) and close<Tsl, message="Sell::{{ticker}}:{{close}}")
num12= input(12, title='ema12')
num30= input(30, title='ema30')
num100= input(100, title='ema100')
num200= input(200, title='ema200')
ema12 = ema(close,num12)
ema30 = ema(close,num30)
ema100 = ema(close,num100)
ema200 = ema(close,num200)
plot(ema12, title='ema12', color=green, linewidth=2)
plot(ema30, title='ema30', color=red, linewidth=2)
plot(ema100, title='ema100', color=blue, linewidth=2)
plot(ema200, title='ema200', color=orange, linewidth=3)
plot(vwap(close), color=black, linewidth=3)
length = input(32, title="Length")
offset = input(0, title="Offset")
src = input(close, title="Source")
lsma = linreg(src, length, offset)
lsma2 = linreg(lsma, length, offset)
eq= lsma-lsma2
zlsma = lsma+eq
length1 = input(20, minval=1)
src1 = input(close, title="Source")
mult1 = input(2.0, minval=0.001, maxval=50)
basis = sma(src1, length1)
dev = mult1 * stdev(src1, length1)
upper = basis + dev
lower = basis - dev
plot(basis, color=red)
p1 = plot(upper, color=blue)
p2 = plot(lower, color=blue)
fill(p1, p2)
我试图将其转换为 v3 但失败了。 然后我尝试将它直接转换为 v5,我能够修复一些小的变化,比如对input.int
的input
,但也会收到很多其他错误消息。
一个错误消息的示例如下:
00:41:23 — Compilation error. Line 5: The arguments 'maxval', 'minval', and 'step' cannot be used with the input() function. You can use the input.int() or input.float() functions to specify a range of input data values
首先将其转换为 v3,然后使用转换器工具将其转换为 v4,然后再转换为 v5。
要将其转换为 v3,您可以参考迁移指南。
您的主要问题将是如下几行:
TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
正如迁移指南告诉您的那样,不再允许使用自引用变量。 所以你应该像下面这样修复这样的语句:
TrendUp = 0.0
TrendUp := close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.