【问题标题】:alert, true or false, changes from true to false and false to true警报,真或假,从真到假,从假到真
【发布时间】:2019-05-29 01:47:02
【问题描述】:

TradingView PineScript 代码。当它从 true 变为 false 和 false 变为 true 时需要一个警报。

//@version=2
study

threshold = input(title="Threshold", type=float, defval=0.0014, 
step=0.0001)



buying = l3_0 > threshold ? true : l3_0 < -threshold ? false : buying[1]

hline(0, title="base line")
//bgcolor(l3_0 > 0.0014 ? green : l3_0 < -0.0014 ? red : gray, transp=20)
bgcolor(buying ? green : red, transp=20)
plot(l3_0, color=silver, style=area, transp=50)
plot(l3_0, color=aqua, title="prediction")

//longCondition = buying
//if (longCondition)
//    strategy.entry("Long", strategy.long)

//shortCondition = buying != true
//if (shortCondition)
//    strategy.entry("Short", strategy.short)

已将其更改为研究。作为一种策略,它发出警报并在图表上绘制方向。将其更改为一项研究,但警报仅应在更改时才发出。在我的研究中,它会提醒每一根蜡烛,而不是改变。我尝试的任何方法都会在每根蜡烛上给出多头或空头。

【问题讨论】:

  • 你看到我对你其他问题的回答了吗? stackoverflow.com/a/56287886/7209631
  • 你认为哪一行给了你警报?你的大部分代码都被注释掉了。
  • 谢谢巴里斯。是的,我确实收到了您的答复。花了几天时间尝试添加到我的脚本中,但无法使其工作。我还在学习代码。了解基础,能看懂部分代码。尝试破解它但无法使其工作。你能帮我看看这个吗?收到任何建议。
  • 嗨,Reportgunner。代码最初是一种策略。因此注释掉了。我把它留在了,因为我认为它可能会有所帮助。进入/退出策略是我在研究中所追求的。只有当它由真变为假或由假变为真时。需要退出买入进入卖出。

标签: pine-script


【解决方案1】:

您可以使用change() 函数来检查变量是否已更改。

//@version=3
study("Custom alert condition", overlay=true)
my_variable = close > open

alertcondition(change(my_variable), title='Triggers when close is above the open or vice versa', message='Candle color changed!')
// this is here because a study chart requires at least one plot, bgcolor or barcolor call
// setting the bar color to na (i.e. N/A) does nothing
barcolor(na)

然后您可以转到右上角的闹钟图标并创建一个使用此自定义条件的新警报。可以选择每分钟触发一次、每条触发一次或其他。


这是一个测试警报条件,看看您是否已正确创建警报,将其设置为每分钟触发一次,它应该会快速触发。

//@version=3
study("Testing condition", overlay=true)
alertcondition(close, title='Triggers when close changes', message='Close has changed!')
barcolor(na)

【讨论】:

    猜你喜欢
    • 2014-02-17
    • 2015-03-30
    • 2014-09-07
    • 2015-12-05
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 2014-10-25
    相关资源
    最近更新 更多