简体   繁体   English

基于百分比的利润目标策略以使用 pinescript 发出警报

[英]% based profit target stragety to Alert with pinescript

im trying to convert strategy to study with percentage based profit target.我正在尝试将策略转换为基于百分比的利润目标进行研究。 but i dont know how to convert.但我不知道如何转换。 Actually im a newbie in this field.实际上我是这个领域的新手。 Im learning script with other users questions or answers.我正在与其他用户的问题或答案一起学习脚本。

Exactly, i want to create Alert "stragety.exit of x0 to x5"确切地说,我想创建警报“x0 到 x5 的 stragety.exit”

Many Thanks~非常感谢~

stopPer = input(1.0, title='Stop Loss %', type=input.float) / 100
takePer = input(26.0, title='Take Profit %', type=input.float) / 100

longStop = strategy.position_avg_price * (1 - stopPer)
shortStop = strategy.position_avg_price * (1 + stopPer)
shortTake = strategy.position_avg_price * (1 - takePer)
longTake = strategy.position_avg_price * (1 + takePer)

strategy.entry("Buy", strategy.long, when = buy)
strategy.entry("sell", strategy.short, when =sell)

if strategy.position_size > 0 
    strategy.exit(id="Close Long", stop=longStop, limit=longTake)
if strategy.position_size < 0 
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake)


strategy.exit("x0", qty_percent = 10, profit = percentAsPoints(1))
strategy.exit("x1", qty_percent = 10, profit = percentAsPoints(3))
strategy.exit("x2", qty_percent = 10, profit = percentAsPoints(5))
strategy.exit("x3", qty_percent = 15, profit = percentAsPoints(10))
strategy.exit("x4", qty_percent = 20, profit = percentAsPoints(15))
strategy.exit("x5", profit = percentAsPoints(20))`

You can create an alert on strategy directly.您可以直接创建策略警报。 You don't need convert it to a study for this.您不需要为此将其转换为研究。 I suggests to start from learning the official docs .我建议从学习官方文档开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM