TradingView-当我做多时,我希望我的止损位于上一个柱的低点

时间:2018-12-14 17:49:48

标签: tradingview-api pine-script

我在TradingView中有一个策略,该策略根据特定条件会持续很长时间。如果我对StopLoss和TakeProfit使用整数或百分比,则效果很好。

但是,我真的想将之前的柱线的止损设置为低。

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

Below不起作用,因为在每个蜡烛上都会更新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

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

1 个答案:

答案 0 :(得分: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