[英]I have experiencing problem to include a mutable variable as an argument for security function
我嘗試在策略中在 ATR 追蹤止損中使用多時間框架。 我不知道如何將這些 arguments 用於安全 function。 問題顯示在最后 3 行中,“不能使用可變變量作為 request.security 函數的參數”
ATRTimeframe = input.timeframe(title="ATR Timeframe", defval="")
ATRPeriod = input.int(10, "ATR Period")
ATRMultiplier = input.float(3, "ATR Multiplier", step=.1)
ATR = ta.atr(ATRPeriod)
Stop = ATRMultiplier*ATR
var ATRTrailingStop = 0.0
ATRTrailingStop := if close>ATRTrailingStop[1] and close[1]>ATRTrailingStop[1]
math.max(ATRTrailingStop[1], close-Stop)
else if close<ATRTrailingStop[1] and close[1]<ATRTrailingStop[1]
math.min(ATRTrailingStop[1], close+Stop)
else if close>ATRTrailingStop[1]
close-Stop
else
close+Stop
var Position = 0.0
Position := if close[1]<ATRTrailingStop[1] and close>ATRTrailingStop[1]
1
else if close[1]>ATRTrailingStop[1] and close<ATRTrailingStop[1]
-1
else
Position[1]
ATRSecure = request.security(syminfo.tickerid, ATRTimeframe, ATRTrailingStop, gaps=barmerge.gaps_off)
PlotColor = Position == -1 ? color.red: Position == 1 ? color.green : color.blue
plot(ATRSecure, color=PlotColor, linewidth=input(1, "Line Width", group=atrGroup), title="ATR Trailing Stop")
您可以在request.security()
中使用可變變量,但前提是您將它們包裝到 function 中。 Security
性從當前交易品種的上下文中提取變量並在不同的交易品種/時間框架上計算它,因此它要求您將所有將變量更改為 function 並請求 function 代替。 以下是您的情況:
<...>
atrStop() =>
var ATRTrailingStop = 0.0
ATRTrailingStop := if close>ATRTrailingStop[1] and close[1]>ATRTrailingStop[1]
math.max(ATRTrailingStop[1], close-Stop)
else if close<ATRTrailingStop[1] and close[1]<ATRTrailingStop[1]
math.min(ATRTrailingStop[1], close+Stop)
else if close>ATRTrailingStop[1]
close-Stop
else
close+Stop
ATRTrailingStop = atrStop()
var Position = 0.0
Position := if close[1]<ATRTrailingStop[1] and close>ATRTrailingStop[1]
1
else if close[1]>ATRTrailingStop[1] and close<ATRTrailingStop[1]
-1
else
Position[1]
ATRSecure = request.security(syminfo.tickerid, ATRTimeframe, atrStop(), gaps=barmerge.gaps_off)
<...>
首先,我在 CFB 認識你嗎? 哈哈。 其次,這里有一些鏈接可以回答您的問題: TradingView 不能使用可變變量作為安全參數 function 不能使用可變變量作為安全參數 function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.