当您为其他时间段的指标设置时间段时,云无法运行(TradingView) [英] cloud not functioning when you set a timeframe for indicator on other timeframes (Tradingview)

查看:22
本文介绍了当您为其他时间段的指标设置时间段时,云无法运行(TradingView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在交易视图上制作了这个指标,它填补了移动平均线之间的距离(它被称为云)当我没有为指标从其中获取数据设置特定的时间框架时,云工作,但例如,当我将指标时间框架设置为每周,并在日线图上查看它时,除了云之外,一切都是正确的,除了您设置了整个指标之外,它不会在其他时间范围内填充(在这个例子中,它只在周线图上起作用,在其他时间范围内它不起作用),你知道我应该做什么来让它工作吗?

StudyName        = "MA Cloud"
ShortStudyName   = "MA cloud" 
study(StudyName, shorttitle=ShortStudyName, overlay=true, resolution="")

source = input(close, title="Source")
typeofMA1 = input(title="Type of Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "TMA", "HullMA", "DEMA", "TEMA", "VWAP"])
length_ma1 = input(30, title = "[ALL but VWAP] Length of Moving Average 1", type=input.integer)
typeofMA2 = input(title="Type of Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "TMA", "HullMA", "DEMA", "TEMA", "VWAP"])
length_ma2 = input(74, title = "[ALL but VWAP] Length of Moving Average 2", type=input.integer)

color_candles = input(true, title="Color based on trend?")

f_smma(src, len) =>
    smma = 0.0
    smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
    smma

f_hullma(src, length) =>
    wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))

f_tma(src, length) =>
    sma(sma(src, length), length)

f_dema(src, length) =>
    emaValue = ema(src, length)
    2 * emaValue - ema(emaValue, length)

f_tema(src, length) =>
    ema1 = ema(src, length)
    ema2 = ema(ema1, length)
    ema3 = ema(ema2, length)
    (3 * ema1) - (3 * ema2) + ema3 

f_ma(smoothing, src, length) =>

    iff(smoothing == "RMA",    rma(src, length), 
     iff(smoothing == "SMA",    sma(src, length),
     iff(smoothing == "EMA",    ema(src, length),
     iff(smoothing == "WMA",    wma(src, length),
     iff(smoothing == "VWMA",   vwma(src, length),
     iff(smoothing == "SMMA",   f_smma(src, length),
     iff(smoothing == "HullMA", f_hullma(src, length),
     iff(smoothing == "VWAP",   vwap(hlc3),
     iff(smoothing == "DEMA",   f_dema(src, length),
     iff(smoothing == "TEMA",   f_tema(src, length), src))))))))))

MA1 = f_ma(typeofMA1, source, length_ma1)
MA2 = f_ma(typeofMA2, source, length_ma2)

plot_ma1 = plot(MA1, color=color.new(color.green, 0), linewidth=3, title = "MA1")
plot_ma2 = plot(MA2, color=color.new(color.red, 0), linewidth=3, title = "MA2")

fill_color = MA1 > MA2 ? color.new(color.green, 60) : color.new(color.red, 60)
fill(plot_ma1, plot_ma2, color=fill_color)

// Candles coloring
clr = not color_candles ? na : 
 MA1 > MA2 ? color.new(color.lime, 40) : color.new(color.fuchsia, 40)

barcolor(clr,title="Trend State Bar Colouring")

cond_buy  = MA1 > MA2 and crossover(MA1, MA2)
cond_sell = MA1 < MA2 and crossunder(MA1, MA2)

// green triangle
plotshape(cond_buy, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.large)
// red triangle
plotshape(cond_sell, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.large)


alertcondition(cond_buy,  title='Buy Alert', message="Buy Alert")
alertcondition(cond_sell,  title='Sell Alert', message="Sell Alert")

推荐答案

如果您在其他时间范围内计算脚本,则这是预期行为。如果您位于60 min图表上,并将您的指示器时间范围设置为1D,则60 min图表的每个会话将仅为您提供1个值。

这与使用security()函数相同。有关这方面的信息可在此处找到:

https://www.tradingview.com/pine-script-docs/en/v5/concepts/Other_timeframes_and_data.html#gaps

&Hidden&Quot;gaps参数(通过resolution参数隐式使用security函数)可以在study()函数中设置为resolution_gaps = false

因此您需要将您的学习电话重写为:

study(StudyName, shorttitle=ShortStudyName, overlay=true, resolution="", resolution_gaps = false)

这篇关于当您为其他时间段的指标设置时间段时,云无法运行(TradingView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆