gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:00:34 27 4
gpt4 key购买 nike

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

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

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

    谢谢

    最佳答案

    这种策略的例子:

    // 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/ 上看到

    关于pine-script - TradingView – Pine Script 中单个订单的多个止盈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61477986/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com