Pinescript TradingView:有条件的卖单和止损

时间:2020-04-11 12:41:37

标签: pine-script

您好,我是Tradingview和pinescript的书呆子。

我的问题是我想在某些情况下从订单中退出并添加止损,请参阅:

strategy.entry("Buy", true, when = crossover(sma(close, 14), sma(close, 28)) // buy order

strategy.close("Buy", when = crossunder(sma(close, 14), sma(close, 28))) // sell order at condition

现在我无法添加止损条件!为什么???唯一的方法是这样:

strategy.exit("STOP","Buy", stop = 100) //sell order at stoploss

我想在交叉交易时卖出股票,但以止损保护我,但这是不可能的...或者我在没有条件的情况下使用本身的 strategy.close 但没有止损或我使用 strategy.exit 有止损和止盈但没有条件!

有一种使用条件和止损工具的方法吗?

谢谢大家。

1 个答案:

答案 0 :(得分:0)

这条线在一起没有给您想要的东西吗?

strategy.entry("Buy", true, when = crossover(sma(close, 14), sma(close, 28)) // buy order

strategy.close("Buy", when = crossunder(sma(close, 14), sma(close, 28))) // sell order at condition

strategy.exit("STOP","Buy", loss = 100) // You need use `loss` param if you whant set up offset from entry price in "points" and doesn't absolute price.