英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论