提问人:Zclaws77 提问时间:10/2/2023 最后编辑:Zclaws77 更新时间:10/4/2023 访问量:49
计算不包括周末的前几天
Count Previous Days Excluding Weekends
问:
此脚本有两个增量问题,
[ ] 交换增量?:计算包括周末在内的所有前几天,但增量不正确,因为标签以更高的增量显示。 (7 DH 450.00), (6 DH 440.00), (5 DH 420.00), (4 DH 410.00), (1 DH 430.00)
[✓] 掉期增量?:计算所有前一个市场交易日,但价格不正确,因为标签都显示相同的价格。 (4 DH 430.00), (3 DH 430.00), (2 DH 430.00), (1 DH 430.00), (0 DH 430.00)
下面是两个增量之间的视觉差异 https://imgur.com/a/MNX7p7p
//@version=5
indicator('Lines & Labels', 'LL', overlay=true, max_lines_count=100, max_labels_count=100)
Levels=input(true, 'Show Levels?', group='Levels', inline='1')
LL=input.int(5, '', minval=1, step=1, group='Levels', inline='1')
ShowBC=input(true, 'Swap Colors?', group='Levels', inline='2')
BC=input(color.rgb(0, 0, 0), '', group='Levels', inline='2')
DHColor=input(color.rgb(0, 150, 136), '', group='Levels', inline='2')
Extra=input(false, 'Swap Increments?', group='Levels')
T(X, T) => str.tostring(X, T)
TX(COLOR) => ShowBC ? BC : COLOR
BG(COLOR) => ShowBC ? COLOR : BC
DD=str.format_time(last_bar_index - time, 'd ')
[DT, DH, DB]=request.security(syminfo.tickerid, 'D', [time, high, barstate.islast], lookahead=barmerge.lookahead_off)
DTC=DT != DT[1]
L() => bar_index + 10
var HIGH=array.new_float(1)
LVL(bool YES, int LookBack, float Highs, color HighColor) =>
var line H1=na
var label H2=na
var H3=array.new_line()
var H4=array.new_label()
END=true ? L() : bar_index
if YES
line.set_x2(H1, END)
label.set_x(H2, END)
if Extra
ExtraCount=array.size(H4)
for i = 0 to ExtraCount > 0 ? ExtraCount -1 : na
Count=ExtraCount -1 -i
label.set_text(array.get(H4, i), T(Count, '0') + ' DH | ' + T(Highs, '0.00'))
H1 := line.new(bar_index, Highs, bar_index, Highs, color=HighColor, style=line.style_solid, width=1)
H2 := label.new(na, Highs, text=DD + 'DH | ' + T(Highs, '0.00'), color=BG(HighColor), textcolor=TX(HighColor), style=label.style_label_left, size=size.small)
array.push(H3, H1)
array.push(H4, H2)
if array.size(H3) > LookBack + 1
line.delete(array.shift(H3))
label.delete(array.shift(H4))
if Levels and barstate.islast and array.size(H3) > 1
for i = 0 to array.size(H3) - 2
line.set_x2(array.get(H3, i), L())
label.set_x(array.get(H4, i), L())
if DTC and not DB
array.set(HIGH, 1, DH)
if Extra == false
LVL(DTC, LL, DH, DHColor)
if Extra
LVL(DTC, LL, DH, DHColor)
简单的解决方法是修复第一个问题,但我在每个可用的时间变量之间交替,仍然没有解决方案。
答:
0赞
Mario
10/2/2023
#1
这是我用来排除天数的......
string group_exclude = "--- Exclude Day of Week"
bool exclude_sunday = input.bool(false, "Sun", inline = group_exclude, group = group_exclude) ? dayofweek.sunday == dayofweek : false
bool exclude_monday = input.bool(false, "Mon", inline = group_exclude, group = group_exclude) ? dayofweek.monday == dayofweek : false
bool exclude_tuesday = input.bool(false, "Tue", inline = group_exclude, group = group_exclude) ? dayofweek.tuesday == dayofweek : false
bool exclude_wednesday = input.bool(false, "Wed", inline = group_exclude, group = group_exclude) ? dayofweek.wednesday == dayofweek : false
bool exclude_thursday = input.bool(false, "Thu", inline = group_exclude, group = group_exclude) ? dayofweek.thursday == dayofweek : false
bool exclude_friday = input.bool(false, "Fri", inline = group_exclude, group = group_exclude) ? dayofweek.friday == dayofweek : false
bool exclude_saturday = input.bool(false, "Sat", inline = group_exclude, group = group_exclude) ? dayofweek.saturday == dayofweek : false
bool is_trading_day = not (exclude_monday or exclude_thursday or exclude_wednesday or exclude_thursday or exclude_friday or exclude_saturday or exclude_sunday)
if is_trading_day
...
我在你的代码中发现了一些错误,你应该解决这些错误......
last_bar_index - time
没有意义,您尝试使用柱计数并从中减去 UNIX 时间。
结果将始终为负数,因为 UNIX 时间是一个很大的数字,而柱线计数则不相上下。barstate.islast
因为里面的参数也没有意义。request.*()
评论
0赞
Zclaws77
10/3/2023
我知道使用last_bar_index - 时间完全没有任何意义。然而,与使用 bar - bar 或 unix - unix 显示完全不同的数字相比,它显示了最接近计算前几天的匹配,使用 timenow - time 有效,但将当前日期格式化为 31 而不是 0。
0赞
Zclaws77
10/4/2023
#2
//@version=5
indicator('Lines & Labels', 'LL', overlay=true, max_lines_count=100, max_labels_count=100)
Levels=input(true, 'Show Levels?', group='Levels', inline='1')
LL=input.int(5, '', minval=1, step=1, group='Levels', inline='1')
ShowBC=input(true, 'Swap Colors?', group='Levels', inline='2')
BC=input(color.rgb(0, 0, 0), '', group='Levels', inline='2')
var DHColor=input(color.rgb(0, 150, 136), 'DH', group='Daily', inline='D')
T(X, T) => str.tostring(X, T)
TX(COLOR) => ShowBC ? BC : COLOR
BG(COLOR) => ShowBC ? COLOR : BC
[DT, DH]=request.security(syminfo.tickerid, 'D', [time, high], lookahead=barmerge.lookahead_off)
DTC=DT != DT[1]
L() => bar_index + 10
LVL(bool YES, int LookBack, float Highs, color HighColor) =>
var line H1=na
var label H2=na
var H3=array.new_line()
var H4=array.new_label()
if YES and Levels
line.set_x2(H1, L())
label.set_x(H2, L())
for i = 0 to array.size(H4) > 0 ? array.size(H4) -1 : na
Count=array.size(H4) -1 -i
label.set_text(array.get(H4, i), T(Count, '0') + ' DH | ' + T(label.get_y(array.get(H4, i)), '0.00'))
H1 := line.new(bar_index, Highs, bar_index, Highs, color=HighColor, style=line.style_solid, width=1)
H2 := label.new(na, Highs, color=BG(HighColor), textcolor=TX(HighColor), style=label.style_label_left, size=size.small)
array.push(H3, H1)
array.push(H4, H2)
if array.size(H3) > LookBack + 1
line.delete(array.shift(H3))
label.delete(array.shift(H4))
if barstate.islast and array.size(H3) > 1
for i = 0 to array.size(H3) - 2
line.set_x2(array.get(H3, i), L())
label.set_x(array.get(H4, i), L())
LVL(DTC, LL, DH, DHColor)
价格是恒定的,因为它需要“label.get_y”。
下一个:索引.js 中未更新的变量
评论