首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TradingView -以松树脚本为一单订单获取多个利润

TradingView -以松树脚本为一单订单获取多个利润
EN

Stack Overflow用户
提问于 2020-04-28 10:26:32
回答 2查看 10.3K关注 0票数 8

我试图实施一个简单的策略,当我收到买入信号时输入一个长,然后我想获得多个利润并设置止损:

  • 销售25%利润
  • 按2%利润销售25%利润
  • 销售25%数量在3%利润
  • 销售25%数量在4%利润
  • 止损在2%<代码>H 210<代码>F 211

我尝试了很多基于strategy.closestrategy.exitstrategy.entry的东西,但是没有发现任何东西是有效的。有人有这种策略的经验吗?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2020-04-29 12:30:50

这种战略的例子如下:

代码语言:javascript
复制
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov

//@version=4
strategy("Multiple %% profit exits example", overlay=false, default_qty_value = 100)

longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)

percentAsPoints(pcnt) =>
    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)

lossPnt = percentAsPoints(2)

strategy.exit("x1", qty_percent = 25, profit = percentAsPoints(1), loss = lossPnt)
strategy.exit("x2", qty_percent = 25, profit = percentAsPoints(2), loss = lossPnt)
strategy.exit("x3", qty_percent = 25, profit = percentAsPoints(3), loss = lossPnt)
strategy.exit("x4", profit = percentAsPoints(4), loss = lossPnt)

profitPercent(price) =>
    posSign = strategy.position_size > 0 ? 1 : strategy.position_size < 0 ? -1 : 0
    (price - strategy.position_avg_price) / strategy.position_avg_price * posSign * 100

p1 = plot(profitPercent(high), style=plot.style_linebr, title = "open profit % upper bound")
p2 = plot(profitPercent(low), style=plot.style_linebr, title = "open profit % lower bound")
fill(p1, p2, color = color.red)

你可以在https://www.tradingview.com/script/kHhCik9f-Multiple-profit-exits-example/上看到它是如何工作的

票数 7
EN

Stack Overflow用户

发布于 2022-08-09 08:08:43

这不是正确的答案,因为,主要的问题是止损,所有数量都退出在不同的id,这是造成问题的时候,我们连接api到交易视图。

只有一些数量会执行,而保持不变。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61477986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档