如何使用下时间框架指标的日末值绘制高时间框架指标?[Pine Script] /[Tradingview]



我写了一个这样的脚本(Pine脚本/Tradingview):

//@version=5
indicator("Normalized (ATR - wise) Relative strength of a stock compared to an index (daily close comparison)", "Normalized (ATR - wise) Relative strength of a stock",precision = 2)
//Input
comparativeTickerId = input.symbol("VNINDEX",title = "Comparative Symbol" )
smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
lengthFastMA = input.int(5,minval=1, title="Fast MA")
lengthSlowMA = input.int(25,minval=1, title="Slow MA")
//Calculation
baseSymbol = request.security(syminfo.tickerid, "60", close)   
fixSymbolBar = request.security(syminfo.tickerid, "D", close[1],barmerge.gaps_off, barmerge.lookahead_on) 
atr_baseSymbol = request.security(syminfo.tickerid, "60", ta.atr(25)) 
normalizeSymbolBar = (baseSymbol-fixSymbolBar)/atr_baseSymbol
comparativeSymbol = request.security(comparativeTickerId, "60", close)   
fixComparativeSymbolbar = request.security(comparativeTickerId, "D", close[1],barmerge.gaps_off, barmerge.lookahead_on)   // correct
atrComparativeSymbol = request.security(comparativeTickerId,"60",ta.atr(25))  
normalizeComparativeSymbol = (comparativeSymbol - fixComparativeSymbolbar)/atrComparativeSymbol
ma_function(source, length) =>
switch smoothing
"RMA" => ta.rma(source, length)
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
=> ta.wma(source, length)

res = (normalizeSymbolBar - normalizeComparativeSymbol)*100
//plot
plot(res,style = plot.style_columns, color = res > 0 ? color.blue : color.orange)
plot(ma_function(res,lengthFastMA), color = ma_function(res,lengthFastMA) > 0 ? #0c5847 : color.red, title = "Fast MA", linewidth = 2)
plot(ma_function(res,lengthSlowMA), style =  plot.style_area, title = 'Slow MA', color = color.gray)

简而言之,这个指标计算的是股票与指数的归一化回报率之差。现在我想在每日时间框架上编写一个指标,使用60分钟时间框架上的ta1 .ema(res,lengthFastMA)的日末值来绘制。例如,假设2022年6月30日下午23点的ta.ema(res,lengthFastMA)在60分钟时间框架上的值为50,这使得2022年6月30日的日时间框架上的指标值也为50。

谁能在这个问题上帮忙?非常感谢
my_timeframe = input.timeframe(title="Custom Timeframe", defval="1", group="Strategy parameters")

changed_data = request.security(syminfo.tickerid, my_timeframe, graph_data, gaps=barmerge.gaps_on)

plot(changed_data , title = "Your custom graph", color=color.orange)

对于版本5:定义时间框架输入允许自定义设置部分,请求安全更新与您的视图不同的时间框架,显示图形。

相关内容

  • 没有找到相关文章