如何通过使用 Pine Script 添加百分比较低的条件来开始多头头寸

how to start a long position by adding a percentage lower condition with Pine Script

我想知道如何以较低的百分比开始做多入场。例如,当均线 20 与均线 50 交叉时,一旦交叉发生,多头入场将仅触发低于价格水平 1%。

您可以在 strategy.entry() 函数上使用 limit 参数。这将设置您愿意进入多头交易的最高价格。在您的情况下,我们会将最高价格设置为发生交叉时 close 价格的 99%。

//@version=5
strategy("My strategy", overlay=true)

ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)

longCondition = ta.crossover(ema20, ema50)
shortCondition = ta.crossunder(ema20, ema50)

if (longCondition)
    strategy.entry("Long", strategy.long, limit=close * 0.99)

if (shortCondition)
    strategy.close_all()

plot(ema20, color=color.green)
plot(ema50, color=color.fuchsia)