gpt4 book ai didi

Pine Script Zigzag Offset(松木笔迹之字形偏移)

转载 作者:bug小助手 更新时间:2023-10-25 15:07:20 64 4
gpt4 key购买 nike



I have struggled a lot with the script but i cant make it work. below is default zigzag code of Pine script all i want is to offset(move into future)

我在剧本上费了很大劲,但我不能让它奏效。下面是Pine脚本的默认Z字形代码,我只想要补偿(移到未来)


its using line.new function but i am unable to make the zigzag move in future if someone could guide me. I Have added offset variable that i want to use to shit/move my zigzag with. Rest of the calculation is fine as its default i just want to have them shifted in future somehow.

它使用线路。新的功能,但我无法使之字形移动在未来,如果有人可以引导我。我已经添加了偏移量变量,我想用它来拉屎/移动我的Z字形。计算的其余部分都很好,因为它是默认的,我只是想在未来以某种方式改变它们。


//@version=5



dev_threshold = input.float(title='Deviation (%)', defval=5.0, minval=0.00001, maxval=100.0)
depth = input.int(title='Depth', defval=10, minval=1)
line_color = input(title='Line Color', defval=#2962FF)
extend_to_last_bar = input(title='Extend to Last Bar', defval=true)
display_reversal_price = input(title='Display Reversal Price', defval=true)
display_cumulative_volume = input(title='Display Cumulative Volume', defval=true)
display_reversal_price_change = input.bool(title='Display Reversal Price Change', defval=true, inline='price rev')
difference_price = input.string('Absolute', '', options=['Absolute', 'Percent'], inline='price rev')
offsets = input.int(100,'offset')

pivots(src, length, isHigh) =>
p = nz(src[length])
if length == 0
[bar_index, p]
else
isFound = true
for i = 0 to length - 1 by 1
if isHigh and src[i] > p
isFound := false
isFound
if not isHigh and src[i] < p
isFound := false
isFound
for i = length + 1 to 2 * length by 1
if isHigh and src[i] >= p
isFound := false
isFound
if not isHigh and src[i] <= p
isFound := false
isFound
if isFound and length * 2 <= bar_index
[bar_index[length], p]
else
[int(na), float(na)]
[iH, pH] = pivots(high, math.floor(depth / 2), true)
[iL, pL] = pivots(low, math.floor(depth / 2), false)

calc_dev(base_price, price) =>
100 * (price - base_price) / base_price

price_rotation_aggregate(price_rotation, pLast, cum_volume) =>
str = ''
if display_reversal_price
str += str.tostring(pLast, format.mintick) + ' '
str
if display_reversal_price_change
str += price_rotation + ' '
str
if display_cumulative_volume
str += '\n' + cum_volume
str
str

caption(isHigh, iLast, pLast, price_rotation, cum_volume) =>
price_rotation_str = price_rotation_aggregate(price_rotation, pLast, cum_volume)
if display_reversal_price or display_reversal_price_change or display_cumulative_volume
if not isHigh
label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, yloc=yloc.belowbar, textcolor=color.red)
else
label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, yloc=yloc.abovebar, textcolor=color.green)

price_rotation_diff(pLast, price) =>
if display_reversal_price_change
tmp_calc = price - pLast
str = difference_price == 'Absolute' ? (math.sign(tmp_calc) > 0 ? '+' : '') + str.tostring(tmp_calc, format.mintick) : (math.sign(tmp_calc) > 0 ? '+' : '-') + str.tostring(math.abs(tmp_calc) * 100 / pLast, format.mintick) + '%'
str := '(' + str + ')'
str
else
''
volume_sum(index1, index2) =>
float CVI = 0
for i = index1 + 1 to index2 by 1
CVI += volume[bar_index - i]
CVI
str.tostring(CVI, format.volume)

var line lineLast = na
var label labelLast = na
var int iLast = 0
var float pLast = 0
var bool isHighLast = true // otherwise the last pivot is a low pivot
var int linesCount = 0

pivotFound(dev, isHigh, index, price) =>
if isHighLast == isHigh and not na(lineLast)
// same direction
if isHighLast ? price > pLast : price < pLast
if linesCount <= 1
line.set_xy1(lineLast, index, price)
line.set_xy2(lineLast, index, price)
label.set_xy(labelLast, index, price)
label.set_text(labelLast, price_rotation_aggregate(price_rotation_diff(line.get_y1(lineLast), price), price, volume_sum(line.get_x1(lineLast), index)))
[lineLast, labelLast, isHighLast, false]
else
[line(na), label(na), bool(na), false]
else
// reverse the direction (or create the very first line)
if na(lineLast)
id = line.new(index, price, index, price, color=line_color, width=2)
lb = caption(isHigh, index, price, price_rotation_diff(pLast, price), volume_sum(index, index))
[id, lb, isHigh, true]
else
// price move is significant
if math.abs(dev) >= dev_threshold
id = line.new(iLast, pLast, index, price, color=line_color, width=2)
lb = caption(isHigh, index, price, price_rotation_diff(pLast, price), volume_sum(iLast, index))
[id, lb, isHigh, true]
else
[line(na), label(na), bool(na), false]


if not na(iH) and not na(iL) and iH == iL
dev1 = calc_dev(pLast, pH)
[id2, lb2, isHigh2, isNew2] = pivotFound(dev1, true, iH, pH)
if isNew2
linesCount += 1
linesCount
if not na(id2)
lineLast := id2
labelLast := lb2
isHighLast := isHigh2
iLast := iH
pLast := pH
pLast
dev2 = calc_dev(pLast, pL)
[id1, lb1, isHigh1, isNew1] = pivotFound(dev2, false, iL, pL)
if isNew1
linesCount += 1
linesCount
if not na(id1)
lineLast := id1
labelLast := lb1
isHighLast := isHigh1
iLast := iL
pLast := pL
pLast
else
if not na(iH)
dev1 = calc_dev(pLast, pH)
[id, lb, isHigh, isNew] = pivotFound(dev1, true, iH, pH)
if isNew
linesCount += 1
linesCount
if not na(id)
lineLast := id
labelLast := lb
isHighLast := isHigh
iLast := iH
pLast := pH
pLast
else
if not na(iL)
dev2 = calc_dev(pLast, pL)
[id, lb, isHigh, isNew] = pivotFound(dev2, false, iL, pL)
if isNew
linesCount += 1
linesCount
if not na(id)
lineLast := id
labelLast := lb
isHighLast := isHigh
iLast := iL
pLast := pL
pLast

var line extend_line = na
var label extend_label = na
if extend_to_last_bar == true and barstate.islast == true
isHighLastPoint = not isHighLast
curSeries = isHighLastPoint ? high : low
if na(extend_line) and na(extend_label)
extend_line := line.new(line.get_x2(lineLast), line.get_y2(lineLast), bar_index, curSeries, color=line_color, width=2)
extend_label := caption(not isHighLast, bar_index, curSeries, price_rotation_diff(line.get_y2(lineLast), curSeries), volume_sum(line.get_x2(lineLast), bar_index))
extend_label

line.set_xy1(extend_line, line.get_x2(lineLast), line.get_y2(lineLast))
line.set_xy2(extend_line, bar_index, curSeries)
label.set_xy(extend_label, bar_index, curSeries)
price_rotation = price_rotation_diff(line.get_y1(extend_line), curSeries)
volume_cum = volume_sum(line.get_x1(extend_line), bar_index)
label.set_text(extend_label, price_rotation_aggregate(price_rotation, curSeries, volume_cum))
label.set_textcolor(extend_label, isHighLastPoint ? color.green : color.red)
label.set_yloc(extend_label, yloc=isHighLastPoint ? yloc.abovebar : yloc.belowbar)

Would really appreciate the help.

会非常感谢你的帮助。


更多回答
优秀答案推荐
更多回答

64 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com