Tradingview Pinescript警报无法按预期工作

时间:2020-05-23 07:05:03

标签: charts pine-script trading technical-indicator

我正在使用以下pinescript,但没有收到预期的警报。我知道这是一个重绘脚本。反向测试工作正常。 长警报设置为“每条关闭一次”,短警报设置为“每条关闭一次”。

意外的行为是 1)很少有几次,尽管没有相应的长警报,但我却收到了短警报(尽管我已经在脚本中注意了,短警报仅在有长警报时才发送)。 2)每小节多个连续的短警报。我知道,在实时栏中,短期条件可能是真实的多次。但是由于我将警报设置为“每小节一次”,因此警报应该仅在第一次出现短路情况时才出现。

请问我做错什么了吗?

谢谢。


created_at  text    eng
0   Sat May 23 02:02:37 +0000 2020  Não conheço um eleitor do Bolsonaro que viu o   I do not know a Bolsonaro voter who saw the
1   Sat May 23 02:03:06 +0000 2020  6 Bolsonaro se apresente neste momento dessa    6 Bolsonaro is present at the moment that
2   Sat May 23 02:03:21 +0000 2020  eta que a nota de repudio pra isso aqui vai se  eta that rejection note to this here will
3   Sat May 23 02:04:32 +0000 2020  573124: Segunda-feira vai está lambendo as b    573124: Monday will is licking the b
4   Sat May 23 02:04:32 +0000 2020  Durante a reunião, Bolsonaro externou sua in    During the meeting, expressed his Bolsonaro in


1 个答案:

答案 0 :(得分:1)

bought变量现在会自动将其值栏保存到bar,而我已删除了脚本中后来的vars重新初始化。似乎在这里工作正常:

//@version=4
study("My Script",overlay = true)

ST = input(true, title = "Activate Strategy Tester")
T_SY = input(2000, title = "Strategy Start Year")
T_SM = input(5, title = "Start Month")
T_SD = input(1, title = "Strategy Start Day")
T_EY = input(2025, title = "Strategy End Year")
T_EM = input(1, title = "End Month")
T_ED = input(1, title = "Strategy End Day")
T_S = timestamp(T_SY, T_SM, T_SD,00,00)
T_E = timestamp(T_EY, T_EM, T_ED,00,00)
T= ST and time >= T_S and time <= T_E 

var bought = false
longcondition = false
shortcondition = false

//once condition is met, send a buy alert and make "bought" equal to true  //to enable selling
if (close <= 8600 and bought==false and T)
    bought := true
    longcondition :=true

//once condition is met, sent a sell alert.
if (bought and close>=9000 and T)  
    shortcondition := true
    bought := false

alertcondition(longcondition,  "Long",  "Long")  
alertcondition(shortcondition,  "short",  "short") 
plotshape(longcondition,  title = "Buy",  text = 'Buy',  style = shape.labelup,   location = location.abovebar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)
plotshape(shortcondition,  title = "Sell",  text = 'Sell',  style = shape.labelup,   location = location.belowbar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)
// For debugging.
plotchar(bought, "bought", "•", location = location.top)

enter image description here