与 SMA 的 pinescript 交叉价格似乎不起作用

pinescript crossover price with SMA does not seem to be working

我想检查价格是否超过 200 SMA 超过给定数量的蜡烛(可定制)。如果是真的,我希望它打开很长时间(我还有其他条件需要稍后添加,但我注意到我的代码在这里已经不起作用)。即使价格未超过 200SMA,它也会在整个图表上开多头。

这是我的:

SMA200  = sma(close, 200)
//PRICE OVER EMA CHECKS
TrendBarsCount = input(5, "Price closes needed above/below 200 MA", minval=1)
emaCrossOver = crossover(close, SMA200)
var emaLongCondition = false
if barssince(emaCrossOver) >= TrendBarsCount
    emaLongCondition := true
strategy.entry("Open Long", strategy.long, when = emaLongCondition)

它似乎根本不关心 SMA,我做错了什么?

这对我有用。检查蜡烛收盘价是否高于 200 SMA,然后等待 5 根蜡烛打开多头。

SMA200  = sma(close, 200)

TrendBarsCount = input(5, "Price closes needed above/below 200 MA", minval=1)
emaCrossOver = crossover(close, SMA200)
longCondition = barssince(emaCrossOver) == TrendBarsCount

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