【问题标题】:pinescript - draw a horizontal line immediately (not at closing) when the price cross over a linepinescript - 当价格越过一条线时立即(不是在收盘时)画一条水平线
【发布时间】:2020-12-29 19:48:18
【问题描述】:

价格上穿 ema10 时开多头,下穿时做空。长目标是l线,短目标是s线。

例如,在做多时,我想在价格越过 l 线时立即(而不是收盘时)画一条水平线。同样,我想在价格穿越 s 线时画一条水平线,简而言之。我无法画线,因为 l 和 s 不是恒定的。我想计算交叉点和交叉点的价格。

Here is an example of a picture

//@version=4
study(title="ema buy sell", overlay=true)
ema1 = ema(close, 10)
l = ema1 * 1.02
s = ema1 * 0.98


plot(ema1, title="Ema 10", color=color.blue, linewidth=1, transp=0)
plot(l, title="Take Long TP", color=color.red, linewidth=2, transp=0)
plot(s, title="Take Short TP", color=color.green, linewidth=1, transp=0)


longCond = crossover(high, ema1)
shortCond = crossunder(low, ema1)

plotshape(series=longCond, title="Long", style=shape.triangleup, location=location.belowbar, color=color.green, text="LONG", size=size.small)
plotshape(series=shortCond, title="Short", style=shape.triangledown, location=location.abovebar, color=color.red, text="SHORT", size=size.small)

【问题讨论】:

    标签: line pine-script crossover


    【解决方案1】:

    此脚本将按照您的描述打印高/高频带分频器上的线。

    //@version=4
    study(title="ema buy sell", overlay=true)
    ema1 = ema(close, 10)
    l = ema1 * 1.02
    s = ema1 * 0.98
    
    plot(ema1, title="Ema 10", color=color.blue, linewidth=1, transp=0)
    plot(l, title="Take Long TP", color=color.red, linewidth=2, transp=0)
    plot(s, title="Take Short TP", color=color.green, linewidth=1, transp=0)
    
    longCond = crossover(high, ema1)
    shortCond = crossunder(low, ema1)
    
    plotshape(series=longCond, title="Long", style=shape.triangleup, location=location.belowbar, color=color.green, text="LONG", size=size.small)
    plotshape(series=shortCond, title="Short", style=shape.triangledown, location=location.abovebar, color=color.red, text="SHORT", size=size.small)
    
    var float lineOnCrossOver = na
    if crossover(high, l)
        lineOnCrossOver := l
    plot(lineOnCrossOver, color = change(lineOnCrossOver)? na : color.green)
    

    【讨论】:

      猜你喜欢
      • 2022-11-23
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多