【问题标题】:How to add the alertcondition() function in my script?如何在我的脚本中添加 alertcondition() 函数?
【发布时间】:2020-01-15 12:28:07
【问题描述】:

我是 TradingView 的新手,目前正在测试 pine 脚本。我从 ChartArt 中选择了一个,它是一个双重指标策略:RSI 和随机指标。

我想知道如何添加警报,但无法弄清楚。 这里的策略:

//@version=2
strategy("Stochastic + RSI, Double Strategy (by ChartArt)", shorttitle="CA_-_RSI_Stoch_Strat", overlay=true)

// ChartArt's Stochastic Slow + Relative Strength Index, Double Strategy
//
// Version 1.0
// Idea by ChartArt on October 23, 2015.
//
// This strategy combines the classic RSI
// strategy to sell when the RSI increases
// over 70 (or to buy when it falls below 30),
// with the classic Stochastic Slow strategy
// to sell when the Stochastic oscillator
// exceeds the value of 80 (and to buy when
// this value is below 20).
//
// This simple strategy only triggers when
// both the RSI and the Stochastic are together
// in overbought or oversold conditions.
//
// List of my work: 
// https://www.tradingview.com/u/ChartArt/


///////////// Stochastic Slow
Stochlength = input(14, minval=1, title="lookback length of Stochastic")
StochOverBought = input(80, title="Stochastic overbought condition")
StochOverSold = input(20, title="Stochastic oversold condition")
smoothK = input(3, title="smoothing of Stochastic %K ")
smoothD = input(3, title="moving average of Stochastic %K")
k = sma(stoch(close, high, low, Stochlength), smoothK)
d = sma(k, smoothD)


///////////// RSI 
RSIlength = input( 14, minval=1 , title="lookback length of RSI")
RSIOverBought = input( 70  , title="RSI overbought condition")
RSIOverSold = input( 30  , title="RSI oversold condition")
RSIprice = close
vrsi = rsi(RSIprice, RSIlength)


///////////// Double strategy: RSI strategy + Stochastic strategy

if (not na(k) and not na(d))

    if (crossover(k,d) and k < StochOverSold)
        if (not na(vrsi)) and (crossover(vrsi, RSIOverSold))
            strategy.entry("LONG", strategy.long, comment="LONG")



if (crossunder(k,d) and k > StochOverBought)
    if (crossunder(vrsi, RSIOverBought))
        strategy.entry("SHORT", strategy.short, comment="SHORT")

为此,我们可以使用函数:alertcondition()。我试图将它直接放在我的条件中,但范围不正确。如果我把它放在脚本中并取回我的 if 语句的条件,那么在测试策略时我不会收到数据。我也无法获得我想要的自定义警报。

我尝试的另一件事是创建两个 bool 参数,它们在良好的 if 语句中变为 true。例如,alertcondition() 中的条件变为 SHORT == true。通过这样做,我得到了以下错误:“添加到图表操作失败,原因:脚本必须至少有一个输出函数调用(例如绘图、条形颜色等)。原因:AST 为空”。

if (not na(k) and not na(d))

    if (crossover(k,d) and k < StochOverSold)
        if (not na(vrsi)) and (crossover(vrsi, RSIOverSold))
            strategy.entry("LONG", strategy.long, comment="LONG")
            SHORT = false
            LONG = true


if (crossunder(k,d) and k > StochOverBought)
    if (crossunder(vrsi, RSIOverBought))
        strategy.entry("SHORT", strategy.short, comment="SHORT")
        SHORT = true
        LONG  = false


alertcondition(SHORT == true, title='SHORT', message='SHORT message') 
alertcondition(LONG == true, title='LONG', message='LONG message') 

关于如何实施这些警报的任何想法?

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    无法为strategy 创建警报。因此,您需要将策略转化为指标。

    请注意,调用该函数不会设置警报。您需要手动执行此操作。

    这是alertconditiondocumentation。它通过示例告诉您您需要知道的一切。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-14
      • 2011-09-14
      • 2021-08-15
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 2021-04-27
      相关资源
      最近更新 更多