[英]I'd like to display the price label at the end of the right screen in the Auto Fib Retention Script, which is a trading view built-in
In the TradingView built-in script, Auto Fib Retention Script, I'd like to pin the label next to the price line at the right end of the screen.在 TradingView 内置脚本 Auto Fib Retention Script 中,我想将 label 固定在屏幕右端的价格线旁边。 scripted:
脚本:
x_draw_label (price, txt, txtColor) =>
x = labelsPosition == "Left" ? line.get_x1(lineLast) : line.get_x2(lineLast)
When you select the right side of the label position, only the maximum line.get_x2(lineLast)
is moved.当你 select 右边的 label position 时,只有最大的
line.get_x2(lineLast)
被移动了。 I would appreciate it if you could tell me how to fix it next to the price line at the end of the right screen.如果您能告诉我如何在右侧屏幕末尾的价格线旁边修复它,我将不胜感激。
//@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)
In the TradingView built-in script, Auto Fib Retention Script, I'd like to pin the label next to the price line at the right end of the screen.在 TradingView 内置脚本 Auto Fib Retention Script 中,我想将 label 固定在屏幕右端的价格线旁边。 scripted:
脚本:
x_draw_label (price, txt, txtColor) =>
x = labelsPosition == "Left" ? line.get_x1(lineLast) : line.get_x2(lineLast)
When you select the right side of the label position, only the maximum line.get_x2(lineLast)
is moved.当你 select label position 的右侧,只有最大的
line.get_x2(lineLast)
被移动。 I would appreciate it if you could tell me how to fix it next to the price line at the end of the right screen.如果您能告诉我如何在右侧屏幕末尾的价格线旁边修复它,我将不胜感激。
//@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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.