Tradingview Pine 脚本在策略进入时保存收盘价

编程入门 行业动态 更新时间:2024-10-23 03:17:17
本文介绍了Tradingview Pine 脚本在策略进入时保存收盘价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

Hey I'm trying to save the close price at the time of strategy.entry to a variable so I can use it later for an exit.

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

我收到错误:未声明的标识符buyprice".据我了解,这意味着该变量在 if 语句之外无效.有没有办法改变这种情况?预先感谢您的帮助

I get the error: Undeclared identifier 'buyprice'. From what I understand this means that the variable is not valid outside of the if statement. Is there a way to change this? Thanks in advance for your help

推荐答案

这是 是我让它发挥作用的唯一方法.

This is the only way that I could get this to work.

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

Basically, you set the previous price when long condition is met and then retrieve that value from the global variables in the next phase.

//@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)

希望这会有所帮助!

更多推荐

Tradingview Pine 脚本在策略进入时保存收盘价

本文发布于:2023-10-25 21:59:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528230.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收盘价   脚本   策略   Tradingview   Pine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!