【问题标题】:Tradingview Pine script save close price at time of strategy entryTradingview Pine 脚本在策略输入时保存收盘价
【发布时间】:2018-08-04 02:48:37
【问题描述】:

嘿,我正在尝试将 strategy.entry 时的收盘价保存到一个变量中,以便以后可以使用它来退出。

if condition
    strategy.entry("long", true)
    buyprice=close
(strategy.exit("exit","long", when = close>buyprice*1.1) 

我收到错误:Undeclared identifier 'buyprice'。据我了解,这意味着该变量在 if 语句之外无效。有没有办法改变这个?提前感谢您的帮助

【问题讨论】:

  • 在全球范围内声明buyprice
  • 为什么这个问题受到保护?只是没有意义......

标签: pine-script


【解决方案1】:

This 是我可以让它工作的唯一方法。

基本上,您在满足多头条件时设置之前的价格,然后在下一阶段从全局变量中检索该值。

//@version=2
...
buyprice=buyprice[1]


golong=...

if golong
    buyprice := close

goshort=... or close<=buyprice*0.95

strategy.entry("Long", long=true, when=golong)
strategy.close("Long", when=goshort)

希望这会有所帮助!

【讨论】:

  • 如此错误和不完整
  • 这个不行,buyprice没有更新
  • 这似乎不起作用,buyprice 在策略期间从未更新,我无法调试它的值以验证它
【解决方案2】:

将此 AFTER 添加到您用于输入位置的代码中:

bought = strategy.position_size[0] > strategy.position_size[1]
entry_price = valuewhen(bought, open, 0)

【讨论】:

  • 什么是函数valuewhen
猜你喜欢
  • 1970-01-01
  • 2018-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多