【发布时间】:2022-08-20 01:26:49
【问题描述】:
我正在基于几个不同的指标在 PineScript 中编写 Tradingview 策略,并且我想根据止损百分比设置止盈目标,例如;如果基于之前最低低点的止损<2.5%,那么我想要5倍的TP,但如果之前的最低低点>2.5%,那么我想要4倍的TP。
这是代码的 TP/SL 部分的当前版本,它不工作。
// ENTRY
strategy.entry(\"LONG\", strategy.long, when=long)
strategy.entry(\"SHORT\", strategy.short, when=short)
// LONG SL & TP
stopPerlong = (close-ta.lowest(low, 10)) / ta.lowest(low, 10)
takePerlong = if stopPerlong > 0.05
stopPerlong * 3
else if stopPerlong > 0.025
stopPerlong * 4
else if stopPerlong < 0.025
stopPerlong * 5
else
na
// SHORT SL & TP
stopPershort = (close-ta.highest(high, 10)) / ta.highest(high, 10)
takePershort = if stopPershort < -0.05
stopPerlong * 3
else if stopPershort < -0.025
stopPerlong * 4
else if stopPershort > -0.025
stopPerlong * 5
else
na
// DEPLOYING TP & SL
longStop = strategy.position_avg_price * (1 - stopPerlong)
shortStop = strategy.position_avg_price * (1 + stopPershort)
shortTake = strategy.position_avg_price * (1 - takePershort)
longTake = strategy.position_avg_price * (1 + takePerlong)
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)
标签: pine-script