如何使用较低时间框架指示器的日末值绘制更高的时间框架指示器?

发布于 2025-02-12 07:00:54 字数 2064 浏览 1 评论 0原文

我编写了这样的脚本:

//@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烙印 2025-02-19 07:00:54
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:定义时间范围输入以允许从设置部分进行自定义,请请求安全更新与您的时间范围不同,该更新与您的视图不同,显示图形。

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)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文