获取蜡烛开盘价的最低价格如何?

huangapple go评论77阅读模式
英文:

How to get the minimum price of the candle on which the was opened?

问题

Pine Script

如何在Pine Script中创建一个链接到我进入交易的蜡烛?
我需要获取交易开始时蜡烛的最低价,以便设置止损。

我尝试在Pine Script参考文档中找到解决方案,但没有成功。

英文:

Pine Script

How to make a link to the candle on which I entered the trade in Pine Script?
I need to get the low of the candle on which the trade was opened in order to put a stop loss there.

I tried to find a solution in the Pine Script reference, but it was not successful.

答案1

得分: 2

我假设你有一个触发你进入交易的变量,类似于 entry_condition。你只需要使用这个变量来检查你的进入条件是否为 true,并将low价格存储在一个var变量中。

var float stop_loss_price = na
stop_loss_price := entry_condition ? low : stop_loss_price // 如果是新的进入条件,存储低价。否则保留其旧值

当你退出一个仓位时,你可能需要重置这个变量。

此外,你需要确保在你已经在交易中时,你的entry_condition不会变为true。否则,它会在交易进行中更新你的止损价格。

英文:

I assume you have a variable that triggers your entry. Soemthing like entry_condition. You just need to use this variable to check if your entry condition is true and store the low price in a var variable.

var float stop_loss_price = na
stop_loss_price := entry_condition ? low : stop_loss_price // If it is a new entry, store the low price. Keep its old value otherwise

You might want to reset this variable when you exit a position.

Also, you need to make sure that your entry_condition does not become true while you are already in a trade. Otherwise, it will update your stop loss price in the middle of a trade.

huangapple
  • 本文由 发表于 2023年3月8日 16:34:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定