止损和退出条件

问题描述 投票:0回答:1

我是一名新手程序员,正在研究 Tradingview Pinescript 策略。这是我的代码。当 RSI 跌破 60 时,我会建立空头头寸。我想在该策略中加入 50 点止损。退出条件是当 RSI 跌破 40,然后跨越 50 以上时,此时我的未平仓头寸应该立即平仓。

如果您需要任何进一步的解释,请告诉我。谢谢!

代码:

//@version=5
strategy(title="RSI", process_orders_on_close=true, use_bar_magnifier=true, overlay=true)

// RSI
rsi = ta.rsi(close, input.int(14, title="RSI Period"))

// Entry
if ta.crossunder(rsi, 60)
    strategy.entry("Enter Short", strategy.short)

// Exit
if ta.crossover(rsi, 50)
    strategy.close("Enter Short", comment="Exit Short")

我尝试使用“stop=50”和“loss=50”来实现止损,但它无法正常运行。

我目前的退出策略似乎有缺陷,因为即使 RSI 跌至 49 然后突破 50 以上,它也会平仓。我要求它至少保持在 40 以下,然后收于 50 以上才能平仓。

pine-script pine-script-v5 trading algorithmic-trading pine-script-v4
1个回答
0
投票

strategy.close()
用于条件关闭。因此,如果您想根据 RSI 值平仓,请使用它。

strategy.exit()
用于根据某个价格退出。如果你想有止损和止盈,就用这个。您可以使用
profit
loss
参数。他们希望在ticks中指定目标。因此,您可能需要将点转换为刻度。

© www.soinside.com 2019 - 2024. All rights reserved.