TradingView – Pine Script 中单个订单的多个止盈

Jul*_*Jul 6 pine-script

我正在尝试实施一个简单的策略,当我收到买入信号时进入多头,然后我想获得多笔利润并设置止损:

  • 以 1% 的利润出售 25% 的数量
  • 以 2% 的利润出售 25% 的数量
  • 以 3% 的利润出售 25% 的数量
  • 以 4% 的利润出售 25% 的数量
  • 止损 2%

我已经尝试了很多基于strategy.close, 的东西strategy.exitstrategy.entry但没有找到任何工作。有没有人有这种策略的经验?

谢谢

And*_*y D 8

这种策略的例子:

\n\n
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/\n// \xc2\xa9 adolgov\n\n//@version=4\nstrategy("Multiple %% profit exits example", overlay=false, default_qty_value = 100)\n\nlongCondition = crossover(sma(close, 14), sma(close, 28))\nif (longCondition)\n    strategy.entry("My Long Entry Id", strategy.long)\n\nshortCondition = crossunder(sma(close, 14), sma(close, 28))\nif (shortCondition)\n    strategy.entry("My Short Entry Id", strategy.short)\n\npercentAsPoints(pcnt) =>\n    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)\n\nlossPnt = percentAsPoints(2)\n\nstrategy.exit("x1", qty_percent = 25, profit = percentAsPoints(1), loss = lossPnt)\nstrategy.exit("x2", qty_percent = 25, profit = percentAsPoints(2), loss = lossPnt)\nstrategy.exit("x3", qty_percent = 25, profit = percentAsPoints(3), loss = lossPnt)\nstrategy.exit("x4", profit = percentAsPoints(4), loss = lossPnt)\n\nprofitPercent(price) =>\n    posSign = strategy.position_size > 0 ? 1 : strategy.position_size < 0 ? -1 : 0\n    (price - strategy.position_avg_price) / strategy.position_avg_price * posSign * 100\n\np1 = plot(profitPercent(high), style=plot.style_linebr, title = "open profit % upper bound")\np2 = plot(profitPercent(low), style=plot.style_linebr, title = "open profit % lower bound")\nfill(p1, p2, color = color.red)\n
Run Code Online (Sandbox Code Playgroud)\n\n

您可以在https://www.tradingview.com/script/kHhCik9f-Multiple-profit-exits-example/上查看其工作原理

\n