为止损创造条件-如果获利+ 5%,则移动TSL以达到收支平衡,否则将其保持在-12%

问题描述

我很好奇这是否可能。目前,我正在使用以下代码在我的头寸上进行11%的追踪止损:

// Trailing Stop Loss Settings
// STEP 1:
// Configure trail stop level with input options (optional)
longTrailPerc = input(title="Trail Long Loss (%)",type=input.float,minval=0.0,step=0.1,defval=11) * 
   0.01

shortTrailPerc = input(title="Trail Short Loss (%)",defval=3) * 
   0.01

// STEP 2:
// Determine trail stop loss prices
longStopPrice = 0.0
shortStopPrice = 0.0

longStopPrice := if strategy.position_size > 0
    stopValue = open * (1 - longTrailPerc)
    max(stopValue,longStopPrice[1])
else
    0

shortStopPrice := if strategy.position_size < 0
    stopValue = close * (1 + shortTrailPerc)
    min(stopValue,shortStopPrice[1])
else
    999999

// Plot stop loss values for confirmation
plot(series=strategy.position_size > 0 ? longStopPrice : na,color=#970000,style=plot.style_line,linewidth=2,title="Long Trail Stop")
plot(series=strategy.position_size < 0 ? shortStopPrice : na,title="Short Trail Stop")

// STEP 3:
// Submit exit orders for trail stop loss price
if strategy.position_size > 0
    strategy.exit(id="Enter Long",stop=longStopPrice,alert_message = message_exit)

if strategy.position_size < 0
    strategy.exit(id="Enter Short",stop=shortStopPrice)

我很好奇是否有可能提出这样一个论点:如果利润= 5%,然后将止损转移到,让我们说收支平衡并从那里开始落后?

(可能的例子吗?如果价格= + 5%,那么LongTrailPerc = 0%)?

其背后的想法是创建一个大小合适的缓冲区,以允许我的位置时间朝我有利的方向移动,但是当它开始朝我有利的方向移动时,再拨更多一点

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...