簡體   English   中英

將此 tradingview pinescript 從 v2 轉換為 v5 時出現問題

[英]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.intinput ,但也會收到很多其他錯誤消息。

一個錯誤消息的示例如下:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM