Pine Script中request.security函数使用报错问题
问题:自动生成的期权合约Ticker在request.security中异常
我尝试绘制所选合约的平值认购期权(ATM Call)收盘价。当前代码可以成功生成正确的ticker ID并在图表添加标签,但使用request.security函数时出现报错,错误信息中的ticker ID与生成的完全不同。手动指定ticker ID则可正常绘制,我无法理解为何expDate和atmStrike值传入request.security后发生变化。
可正常生成Ticker的代码
//@version=6 indicator("My script") import protradingart/pta_plot/12 as pta // Strike width of NIFTY strikeWidth = 50 // finding ATM Strike atmStrike = strikeWidth * (math.round(close / strikeWidth)) // getting the expiry date for FNO (From imported Library) expDate = pta.getExpiry("Monthly", "Thursday", 0, "yyMMdd") // Converting to string string atmCallTicker = syminfo.tickerid + expDate + 'C' + str.tostring(atmStrike) // adding label if barstate.islast label.new(time + 1, close, atmCallTicker, xloc.bar_time, color = color.gray, style = label.style_label_left, force_overlay = true)
触发报错的代码片段
// Requesting the cmp of the ATM Ticker atmCallPrice = request.security(atmCallTicker, '1D', close) // Plotting the ATM Ticker plot(atmCallPrice)
手动指定Ticker可正常运行的代码
// Requesting the cmp of the ATM Ticker atmCallPrice = request.security('NSE:NIFTY250424C22850', '1D', close) // Plotting the ATM Ticker plot(atmCallPrice)
内容的提问来源于stack exchange,提问作者Kunthu Dhadda
相关产品推荐
相关产品推荐

