使用底部指标在主图表上绘制标签
Drawing labels on main chart with bottom indicator
我正在尝试使用指标脚本解决两个问题。
- 这是一个底部指标,我想在主图上画标签。如何?我想不通。
- 其次,我设置绘制标签的条件的方式会在多个蜡烛上绘制。我如何限制它只在第一次出现时绘制?
这是我使用的示例代码。我很感激这里的任何帮助。
study("Trend Up and Down", overlay=false)
l = label.new(bar_index, na)
//buy label
if plus > minus
label.set_text(l, "B")
label.set_color(l, color.green)
label.set_yloc(l, yloc.belowbar)
label.set_style(l, label.style_labelup)
//sell label
if plus < minus
label.set_text(l, "S")
label.set_color(l, color.red)
label.set_yloc(l, yloc.abovebar)
label.set_style(l, label.style_labeldown)
也许我忘了添加 plus
和 minus
的计算方式。为简单起见,我们假设这是一个简单的移动平均线交叉。我是否必须使用 crossover
进行布尔比较,或者我的方法 plus > minus
是标记蜡烛的正确方法吗?
第一个问题已经回答。无法在不同的面板上绘制标签。仅供参考
下面是如何在图表上仅绘制最新信号的示例。
//@version=4
study("Trend Up and Down", overlay=true)
var l = label.new(0,0)
_smaSlow=sma(close, 200)
_smaFast=ema(close, 50)
_longCond = crossover(_smaFast, _smaSlow)
_shortCond = crossunder(_smaFast, _smaSlow)
if(_longCond)
label.set_x(l, bar_index)
label.set_yloc(l, yloc.belowbar)
label.set_style(l, label.style_label_up)
label.set_text(l, "Buy")
label.set_color(l, color.green)
if(_shortCond)
label.set_x(l, bar_index)
label.set_yloc(l, yloc.abovebar)
label.set_style(l, label.style_label_down)
label.set_text(l, "Sell")
label.set_color(l, color.red)
plot(_smaSlow, color=color.blue)
plot(_smaFast, color=color.orange)
在图表上绘制所有买入和卖出信号更为常见,下面是一个示例。
//@version=4
study("Trend Up and Down", overlay=true)
_smaSlow=sma(close, 200)
_smaFast=ema(close, 50)
_longCond = crossover(_smaFast, _smaSlow)
_shortCond = crossunder(_smaFast, _smaSlow)
plotshape(_longCond, size=size.small, style=shape.triangleup, color=color.green, location=location.belowbar, text="Buy")
plotshape(_shortCond, size=size.small, style=shape.triangledown, color=color.red, location=location.abovebar, text="Sell")
plot(_smaSlow, color=color.blue)
plot(_smaFast, color=color.orange)
我正在尝试使用指标脚本解决两个问题。
- 这是一个底部指标,我想在主图上画标签。如何?我想不通。
- 其次,我设置绘制标签的条件的方式会在多个蜡烛上绘制。我如何限制它只在第一次出现时绘制?
这是我使用的示例代码。我很感激这里的任何帮助。
study("Trend Up and Down", overlay=false)
l = label.new(bar_index, na)
//buy label
if plus > minus
label.set_text(l, "B")
label.set_color(l, color.green)
label.set_yloc(l, yloc.belowbar)
label.set_style(l, label.style_labelup)
//sell label
if plus < minus
label.set_text(l, "S")
label.set_color(l, color.red)
label.set_yloc(l, yloc.abovebar)
label.set_style(l, label.style_labeldown)
也许我忘了添加 plus
和 minus
的计算方式。为简单起见,我们假设这是一个简单的移动平均线交叉。我是否必须使用 crossover
进行布尔比较,或者我的方法 plus > minus
是标记蜡烛的正确方法吗?
第一个问题已经回答。无法在不同的面板上绘制标签。仅供参考
下面是如何在图表上仅绘制最新信号的示例。
//@version=4
study("Trend Up and Down", overlay=true)
var l = label.new(0,0)
_smaSlow=sma(close, 200)
_smaFast=ema(close, 50)
_longCond = crossover(_smaFast, _smaSlow)
_shortCond = crossunder(_smaFast, _smaSlow)
if(_longCond)
label.set_x(l, bar_index)
label.set_yloc(l, yloc.belowbar)
label.set_style(l, label.style_label_up)
label.set_text(l, "Buy")
label.set_color(l, color.green)
if(_shortCond)
label.set_x(l, bar_index)
label.set_yloc(l, yloc.abovebar)
label.set_style(l, label.style_label_down)
label.set_text(l, "Sell")
label.set_color(l, color.red)
plot(_smaSlow, color=color.blue)
plot(_smaFast, color=color.orange)
在图表上绘制所有买入和卖出信号更为常见,下面是一个示例。
//@version=4
study("Trend Up and Down", overlay=true)
_smaSlow=sma(close, 200)
_smaFast=ema(close, 50)
_longCond = crossover(_smaFast, _smaSlow)
_shortCond = crossunder(_smaFast, _smaSlow)
plotshape(_longCond, size=size.small, style=shape.triangleup, color=color.green, location=location.belowbar, text="Buy")
plotshape(_shortCond, size=size.small, style=shape.triangledown, color=color.red, location=location.abovebar, text="Sell")
plot(_smaSlow, color=color.blue)
plot(_smaFast, color=color.orange)