为什么未激活利润目标?

发布于 2025-01-25 01:54:38 字数 1026 浏览 3 评论 0原文

我有以下代码,当我有特定价格或特定停止损失的贸易信号出售时,我正在尝试。

但是Trandingview总是以1.3%的价格销售,而不是4%,您是否知道为什么会发生这种情况?

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mpempi

//@version=5

strategy("Strategy HOLD", overlay = true)

rsi = ta.rsi(close, 14)

inTrade = strategy.position_size > 0
notInTrade = strategy.position_size <= 0
timeperiod = time >= timestamp(syminfo.timezone, 2021, 01, 01)

active = rsi > 70

active_close = close < ma200

buy_price = ta.valuewhen(notInTrade, close[1] + close[1] * 4 / 100, 1)
stop_price = ta.valuewhen(notInTrade, close[1] - close[1] * 1 / 100, 1)

if timeperiod and active
    strategy.entry('long', strategy.long)

strategy.exit('long', profit = buy_price, stop = stop_price)

bgcolor(activate_long ? color.new(color.green, 50): na)
bgcolor(activate_buy ? color.new(color.purple, 50): na)
plot(buy_price, color = color.new(color.green, 0))
plot(stop_price, color = color.new(color.yellow, 0))

I have the following code, and I am trying when I have a trade signal to sell at a specific price or a specific stop loss.

But Trandingview always sells at 1.3% up and not at 4%, do you have any idea why this is happening?

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mpempi

//@version=5

strategy("Strategy HOLD", overlay = true)

rsi = ta.rsi(close, 14)

inTrade = strategy.position_size > 0
notInTrade = strategy.position_size <= 0
timeperiod = time >= timestamp(syminfo.timezone, 2021, 01, 01)

active = rsi > 70

active_close = close < ma200

buy_price = ta.valuewhen(notInTrade, close[1] + close[1] * 4 / 100, 1)
stop_price = ta.valuewhen(notInTrade, close[1] - close[1] * 1 / 100, 1)

if timeperiod and active
    strategy.entry('long', strategy.long)

strategy.exit('long', profit = buy_price, stop = stop_price)

bgcolor(activate_long ? color.new(color.green, 50): na)
bgcolor(activate_buy ? color.new(color.purple, 50): na)
plot(buy_price, color = color.new(color.green, 0))
plot(stop_price, color = color.new(color.yellow, 0))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2025-02-01 01:54:39

您的计算似乎熄灭了。

另外,利润 strategy.exit()函数的参数期望在tick中进行目标。

如果您想将TP占4%,SL为1%,请使用以下模板。

tp_per = input.float(4.0, "TP %", minval=0.0, step=0.1) * 0.01
sl_per = input.float(1.0, "TP %", minval=0.0, step=0.1) * 0.01

tp_price = strategy.position_avg_price * (1 + tp_per)
sl_price = strategy.position_avg_price * (1 - sl_per)

if timeperiod and active
    strategy.entry('long', strategy.long)

if (strategy.position_size > 0)
    strategy.exit('long', limit=tp_price, stop=sl_price)

You calculations seem off.

Also, profit argument of the strategy.exit() function expect the target in ticks.

If you want to have a TP at 4% and SL at 1%, use the following template.

tp_per = input.float(4.0, "TP %", minval=0.0, step=0.1) * 0.01
sl_per = input.float(1.0, "TP %", minval=0.0, step=0.1) * 0.01

tp_price = strategy.position_avg_price * (1 + tp_per)
sl_price = strategy.position_avg_price * (1 - sl_per)

if timeperiod and active
    strategy.entry('long', strategy.long)

if (strategy.position_size > 0)
    strategy.exit('long', limit=tp_price, stop=sl_price)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文