我正在尝试根据进入时的低位波动设置静态止损。但是当我尝试以下操作时,止损不断变化,因为有新的最低低点
SwingLowBars=20
longStop = lowest(low, SwingLowBars)[1]
longTake = strategy.position_avg_price + ((strategy.position_avg_price-longStop)*3)
我想要一个函数,该函数在位置上每增加一个新蜡烛时就向SwingLowBars变量中添加+1,以便longTake保持静态,并且当最低柱超过20条时不会改变
你可以将SL值存储在“ var”变量中:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=4
strategy("My Strategy", overlay=true)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
SwingLowBars=20
longStop = lowest(low, SwingLowBars)[1]
var sl = float(na)
if strategy.position_size !=0 and strategy.position_size[1] == 0
sl := strategy.position_avg_price - ((strategy.position_avg_price-longStop)*3)
strategy.exit("x", stop = sl)