价格上穿 ema10 时开多头,下穿时做空。长目标是l线,短目标是s线。
例如,在做多时,我想在价格越过 l 线时立即(而不是收盘时)画一条水平线。同样,我想在价格穿越 s 线时画一条水平线,简而言之。我无法画线,因为 l 和 s 不是恒定的。我想计算交叉点和交叉点的价格。
//@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)