将标签添加到EMA行

时间:2019-09-18 16:08:19

标签: pine-script

想知道是否有人可以帮助在我的EMA行中添加表格,即30号应该有一个标签,上面写着30mins,60 = 1h 240 = 4hrs D = 1 Day ........

非常感谢您的帮助,我是编程的新手。

    //@version=4
study(title="MutiTimeFrame_6EMA", shorttitle="MTF_6EMA", overlay=true)

len3 = input(200, minval=1, title="Length3")
res3 = input(title="EMA3", type=input.resolution, defval="30")

len4 = input(200, minval=1, title="Length4")
res4 = input(title="EMA4", type=input.resolution, defval="60")

len5 = input(200, minval=1, title="Length5")
res5 = input(title="EMA5", type=input.resolution, defval="240")

len6 = input(200, minval=1, title="Length6")
res6 = input(title="EMA6", type=input.resolution, defval="D")


src = input(close, title="Source")

EMA_out_3 = security(syminfo.tickerid, res3, ema(src, len3))
EMA_out_4 = security(syminfo.tickerid, res4, ema(src, len4))
EMA_out_5 = security(syminfo.tickerid, res5, ema(src, len5))
EMA_out_6 = security(syminfo.tickerid, res6, ema(src, len6))

plot(EMA_out_3, color=color.red, linewidth=1, title="EMA3")
plot(EMA_out_4, color=color.aqua, linewidth=2, title="EMA4")
plot(EMA_out_5, color=color.yellow, linewidth=2, title="EMA5")
plot(EMA_out_6, color=color.red, linewidth=2, title="EMA6")

1 个答案:

答案 0 :(得分:0)

此代码显示了两种方法:

//@version=4
study(title="MutiTimeFrame_6EMA", shorttitle="MTF_6EMA", overlay=true)

len3 = input(200, minval=1, title="Length3")
res3 = input(title="EMA3", type=input.resolution, defval="30")

len4 = input(200, minval=1, title="Length4")
res4 = input(title="EMA4", type=input.resolution, defval="60")

len5 = input(200, minval=1, title="Length5")
res5 = input(title="EMA5", type=input.resolution, defval="240")

len6 = input(200, minval=1, title="Length6")
res6 = input(title="EMA6", type=input.resolution, defval="D")


src = input(close, title="Source")

EMA_out_3 = security(syminfo.tickerid, res3, ema(src, len3))
EMA_out_4 = security(syminfo.tickerid, res4, ema(src, len4))
EMA_out_5 = security(syminfo.tickerid, res5, ema(src, len5))
EMA_out_6 = security(syminfo.tickerid, res6, ema(src, len6))

plot(EMA_out_3, color=color.red, linewidth=1, title="EMA3")
plot(EMA_out_4, color=color.aqua, linewidth=2, title="EMA4")
plot(EMA_out_5, color=color.yellow, linewidth=2, title="EMA5")
plot(EMA_out_6, color=color.red, linewidth=2, title="EMA6")

// Method 1
offs = 10
plotshape(EMA_out_3[offs], style=shape.labeldown, location=location.absolute, color=color.red,  textcolor=color.new(color.white,0), show_last=1, text="30mins", offset=-offs, transp=50, title="30 mins")
plotshape(EMA_out_3[offs], style=shape.labeldown, location=location.absolute, color=color.red,  textcolor=color.new(color.white,0), show_last=1, text="30 mins", offset=-offs, transp=50, title="30 mins")

// Method 2
f_lineLabel( _label,_line, _barsBack, _color, _text) =>
    label.delete(_label)
    label.new(
      time - _barsBack * (time - time[1]),
      _line[_barsBack],
      xloc = xloc.bar_time,
      yloc = yloc.price,
      text = _text +"\n" + tostring(_line[_barsBack]),
      color = _color,
      textcolor = color.new(color.white, 0),
      size = size.small)

var ema3Label = label(na)
ema3Label := f_lineLabel(ema3Label, EMA_out_3, 0, color.red, "30 mins")

enter image description here