【问题标题】:My stop loss isn't working on my pine script for tradingview我的止损在我用于交易视图的 pine 脚本上不起作用
【发布时间】:2022-11-10 02:34:05
【问题描述】:

我对编码非常陌生,并制作了以下参数来自动化我的交易策略。我的止损不起作用,我没有解释为什么。

此外,我认为我的 TP 和 SL 被翻转了,但即使翻转了 TP 有效,但 SL 却没有。这里是脚本提到 SL 和 TP 的地方。一定是哪里出了问题。

p=input.float(2.0,"Desired Profit %")
sl= input.float(1,"Desired Stop loss %")
TP  = strategy.position_avg_price * (1 + (p* 0.01))
SL = strategy.position_avg_price * (1 - (sl* 0.01))

if long
    strategy.entry("Long", strategy.long)
if short
    strategy.entry("Short", strategy.short)


strategy.exit("Exit", "Long",limit=TP)
strategy.exit("Exit", "Long",limit=SL)

strategy.exit("Exit", "Short",limit=TP)
strategy.exit("Exit", "Short",limit=SL)

【问题讨论】:

    标签: bots pine-script trading algorithmic-trading tradingview-api


    【解决方案1】:

    您需要使用strategy.exit()stop 参数作为止损。你可以而且应该在同一个调用中同时使用limitstop,除非你想部分关闭。

    strategy.exit("Long Exit", "Long", limit=TP, stop=SL)
    strategy.exit("Short Exit", "Short", limit=TP, stop=SL)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      • 2021-12-14
      相关资源
      最近更新 更多