【问题标题】:pinescript crossover price with SMA does not seem to be working使用 SMA 的 pinescript 交叉价格似乎不起作用
【发布时间】:2021-09-14 10:10:12
【问题描述】:

我想检查价格超过 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,我做错了什么?

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    这对我有用。检查蜡烛是否收于 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)
    

    【讨论】:

      猜你喜欢
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 2011-08-18
      • 2016-11-29
      • 2016-02-01
      • 2020-09-23
      • 2010-12-05
      • 2011-06-14
      相关资源
      最近更新 更多