0

我在 TradingView 中有一个根据特定条件做多的策略。如果我对止损和止盈使用整数或百分比,效果会很好。

但是,我真的想将止损设置在之前的低点。

在执行 Long 时,我似乎无法保存变量。

下面不起作用,因为每根蜡烛都会更新 low[1]:

inpTakeProfit   = input(2.0, title='Take Profit %', type=float)/100
takeProfitValue = strategy.position_avg_price * (1 + inpTakeProfit)
inpStopLoss     = low[1]
stopLossValue = inpStopLoss
entry = strategy.position_avg_price
useTakeProfit   = inpTakeProfit  > 0 ?  takeProfitValue : na
useStopLoss     = inpStopLoss    > 0 ?  stopLossValue   : na

如何保存变量并使其保持静态?

4

1 回答 1

0
//Stop as last bars low and profit as percentage
entry = strategy.position_avg_price
inpTakeProfit   = input(2.0, title='Take Profit %', type=float)/100
takeProfitValue = strategy.position_avg_price * (1 + inpTakeProfit)
useTakeProfit   = inpTakeProfit  > 0 ?  takeProfitValue : na
**inpStopLoss     = valuewhen(allConditions, low, 0)**
stopLossValue = inpStopLoss
useStopLoss     = inpStopLoss    > 0 ?  stopLossValue   : na
于 2018-12-14T21:48:11.043 回答