如何使用较低时间框架指示器的日末值绘制更高的时间框架指示器?
我编写了这样的脚本:
//@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分钟的时间范围内使用TA.EMA(RES,LENGTHESFASTMA)的日末值在每天的时间范围内编写指示器。例如,可以说60分钟时间的2022年6月30日bar ta.ema(res,Lengthfastma)的价值为50,这使得指标的价值在2022年6月30日的日常时间范围内也为50。
我该如何实现?
I have written a script like this:
//@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)
In short, this indicator calculate the different between the normalized return of a stock compared to that of an index.
Now I want to write an indicator on daily time frame using the end-of-day value of ta.ema(res,lengthFastMA) on 60 mins time frame to plot. For example, lets say the value of ta.ema(res,lengthFastMA) of 23 pm June 30th 2022 bar on 60 mins timeframe is 50, that makes the value of the indicator on daily time frame for June 30th 2022 is 50 too.
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于版本5:定义时间范围输入以允许从设置部分进行自定义,请请求安全更新与您的时间范围不同,该更新与您的视图不同,显示图形。
For version 5: define timeframe input to allow customize from settings section, request security update with your timeframe that is different than deafult for your view, show graph.