我正在尝试实施一个简单的策略,当我收到买入信号时进入多头,然后我想获得多笔利润并设置止损:
我已经尝试了很多基于strategy.close
, 的东西strategy.exit
,strategy.entry
但没有找到任何工作。有没有人有这种策略的经验?
谢谢
这种策略的例子:
\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 归档时间: |
|
查看次数: |
4944 次 |
最近记录: |