本文介绍了我想要在Auto Fib保留脚本的右侧屏幕末尾显示价格标签,这是一个内置的交易视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在TradingView内置脚本Auto Fib Return脚本中,我想将标签固定在屏幕右端的价格线旁边。已编写脚本:
x_draw_label (price, txt, txtColor) =>
x = labelsPosition == "Left" ? line.get_x1(lineLast) : line.get_x2(lineLast)
当您选择标签位置的右侧时,仅移动最大值line.get_x2(lineLast)
。如果你能告诉我如何解决这个问题,我将不胜感激。//@version=4
study("Auto Fib Retracement", overlay=true)
// pivots threshold
threshold_multiplier = input(title="Deviation", type=input.float, defval=3, minval=0)
dev_threshold = atr(10) / close * 100 * threshold_multiplier
depth = input(title="Depth", type=input.integer, defval=10, minval=1)
var extendLeft = input(false, "Extend Lines Left")
var extendRight = input(true, "Extend Lines Right")
var extending = extend.none
if extendLeft and extendRight
extending := extend.both
if extendLeft and not extendRight
extending := extend.left
if not extendLeft and extendRight
extending := extend.right
reverse = input(false, "Reverse")
prices = input(true, "Prices")
levels = input(true, "Levels")
levelsFormat = input("Values", "Levels Format", options = ["Values", "Percent"])
labelsPosition = input("Left", "Labels Position", options = ["Left", "Right"])
var line lineLast = na
var int iLast = 0
var int iPrev = 0
var float pLast = 0
var isHighLast = false // otherwise the last pivot is a low pivot
pivots(src, length, isHigh) =>
l2 = length * 2
c = nz(src[length])
ok = true
for i = 0 to l2
if isHigh and src[i] > c
ok := false
if not isHigh and src[i] < c
ok := false
if ok
[bar_index[length], c]
else
[int(na), float(na)]
[iH, pH] = pivots(high, depth / 2, true)
[iL, pL] = pivots(low, depth / 2, false)
calc_dev(base_price, price) =>
100 * (price - base_price) / price
pivotFound(dev, isHigh, index, price) =>
if isHighLast == isHigh and not na(lineLast)
// same direction
if isHighLast ? price > pLast : price < pLast
line.set_xy2(lineLast, index, price)
[lineLast, isHighLast]
else
[line(na), bool(na)]
else // reverse the direction (or create the very first line)
if abs(dev) > dev_threshold
// price move is significant
id = line.new(iLast, pLast, index, price, color=color.gray, width=1, style=line.style_dashed)
[id, isHigh]
else
[line(na), bool(na)]
if not na(iH)
dev = calc_dev(pLast, pH)
[id, isHigh] = pivotFound(dev, true, iH, pH)
if not na(id)
if id != lineLast
line.delete(lineLast)
lineLast := id
isHighLast := isHigh
iPrev := iLast
iLast := iH
pLast := pH
else
if not na(iL)
dev = calc_dev(pLast, pL)
[id, isHigh] = pivotFound(dev, false, iL, pL)
if not na(id)
if id != lineLast
line.delete(lineLast)
lineLast := id
isHighLast := isHigh
iPrev := iLast
iLast := iL
pLast := pL
_draw_line(price, col) =>
var id = line.new(iLast, price, bar_index, price, color=col, width=1, extend=extending)
if not na(lineLast)
line.set_xy1(id, line.get_x1(lineLast), price)
line.set_xy2(id, line.get_x2(lineLast), price)
****_draw_label(price, txt, txtColor) =>
x = labelsPosition == "Left" ? line.get_x1(lineLast) : line.get_x2(lineLast)
var id = label.new(x=x, y=price, text=txt, textcolor=txtColor, style=label.style_none)
label.set_xy(id, x, price)
label.set_text(id, txt)
label.set_textcolor(id, txtColor)****
_wrap(txt) =>
"(" + tostring(txt, "#.##") + ")"
_label_txt(level, price) =>
l = levelsFormat == "Values" ? tostring(level) : tostring(level * 100) + "%"
(levels ? l : "") + (prices ? _wrap(price) : "")
sl1 = input(true, "0")
vall1 = 0.000
sl2 = input(true, "0.236")
vall2 = 0.236
sl3 = input(true, "0.382")
vall3 = 0.382
sl4 = input(true, "0.5")
vall4 = 0.5
sl5 = input(true, "0.618")
vall5 = 0.618
sl6 = input(true, "0.786")
vall6 = 0.786
sl7 = input(true, "1")
vall7 = 1
sl8 = input(true, "1.272")
vall8 = 1.272
sl9 = input(true, "1.414")
vall9 = 1.414
sl10 = input(true, "1.618")
vall10 = 1.618
_draw_retracement(startPrice, endPrice) =>
iHL = startPrice > endPrice
diff = (iHL ? -1 : 1) * abs(startPrice - endPrice)
if sl1
l1 = startPrice + diff * vall1
_draw_line(l1, #808080)
_draw_label(l1, _label_txt(vall1, l1), #808080)
if sl2
l2 = startPrice + diff * vall2
_draw_line(l2, #a61c00)
_draw_label(l2, _label_txt(vall2, l2), #a61c00)
if sl3
l3 = startPrice + diff * vall3
_draw_line(l3, #95cc28)
_draw_label(l3, _label_txt(vall3, l3), #95cc28)
if sl4
l4 = startPrice + diff * vall4
_draw_line(l4, #28cc28)
_draw_label(l4, _label_txt(vall4, l4), #28cc28)
if sl5
l5 = startPrice + diff * vall5
_draw_line(l5, #28cc95)
_draw_label(l5, _label_txt(vall5, l5), #28cc95)
if sl6
l6 = startPrice + diff * vall6
_draw_line(l6, #2895cc)
_draw_label(l6, _label_txt(vall6, l6), #2895cc)
if sl7
l7 = startPrice + diff * vall7
_draw_line(l7, #808080)
_draw_label(l7, _label_txt(vall7, l7), #808080)
if sl8
l8 = startPrice + diff * vall8
_draw_line(l8, #82CA89)
_draw_label(l8, _label_txt(vall8, l8), #82CA89)
if sl9
l9 = startPrice + diff * vall9
_draw_line(l9, #F32C42)
_draw_label(l9, _label_txt(vall9, l9), #F32C42)
if sl10
l10 = startPrice + diff * vall10
_draw_line(l10, #2796ED)
_draw_label(l10, _label_txt(vall10, l10), #2796ED)
p1 = reverse ? line.get_y1(lineLast) : pLast
p2 = reverse ? pLast : line.get_y1(lineLast)
_draw_retracement(p1, p2)
推荐答案
使用:
_draw_label(price, txt, txtColor) =>
x = labelsPosition == "Left" ? line.get_x1(lineLast) : bar_index
var id = label.new(x=x, y=price, text=txt, textcolor=txtColor, style=label.style_none)
label.set_xy(id, x, price)
label.set_text(id, txt)
label.set_textcolor(id, txtColor)
这篇关于我想要在Auto Fib保留脚本的右侧屏幕末尾显示价格标签,这是一个内置的交易视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!