【问题标题】:Strategy does not enter trades策略不进入交易
【发布时间】:2021-03-12 22:57:40
【问题描述】:

我的代码没有显示任何错误,但是当我尝试启动它时,没有提供任何条目,除此之外,我想添加一些额外的过滤器:

  • RSI >50(做多时)
  • SlowEMA > SMA(做多时)
  • 关闭 > SlowEMA(做多时)

有什么建议吗?

FastEMA = ema(close,9) // EMA Fast 9 periods
plot(FastEMA,color=color.fuchsia)
SlowEMA = ema(close,26) // EMA Slow 26 periods
plot(SlowEMA,color=color.blue)
plot(sma(close,200),color=color.gray) // SMA 200 periods
rsi = rsi(close, 14) // Relative strength index

// Donchian Channel

length = input(20, minval=1) 
lower = lowest(length)
upper = highest(length)
basis = avg(upper, lower)
u = plot(upper, "Upper", color=#FF9400)
l = plot(lower, "Lower", color=#FF9400)

// Specify crossover conditions

longCondition = crossover(FastEMA, SlowEMA)
shortCondition = crossunder(FastEMA, SlowEMA)

// Execution

if (longCondition)
    strategy.entry("long", strategy.long, 100)

【问题讨论】:

  • 您可以尝试将plot(longCondition ? 1 : 0) 添加到您的脚本中,看看当情节的值为1 时是否有一些条。也许条件总是错误的。
  • 好主意,谢谢@AndreyD

标签: pine-script algorithmic-trading back-testing


【解决方案1】:

您还必须添加一个函数来退出仓位,例如 strategy.order、strategy.close 或 strategy.exit。

举个例子,如果你在进入交易后退出 5 个柱,你可以选择

if (barssince(change(strategy.opentrades)) == 5)
    strategy.close("long", comment = "timeout")  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    • 2023-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多