pine-script - IB数据的选定时间段进行数据分析
问题描述
整个下午,
以下脚本捕获市场开放时间(伦敦、纽约和亚洲)的初始余额(前 60 分钟内的第一个最高和最低价格)。
IB 的构建发生在前 60 分钟内,然后显示,例如伦敦 0800 到 0900 IB 构建并显示 0900 之后。
然后脚本查看三个 IB 高点并计算出最高点并绘制它(在下面的脚本中显示为白线)。
我正在努力解决的是如何排除新 IB 的建设阶段开始发挥作用。下面的图片应该有助于解释这一点:
我将如何排除蓝色图的 IB 构建阶段,在那 1 小时内,紫色和黄色将仅包含在计算中,而白线将继续在最高高度,不包括 IB 构建。
如果需要,我可以进一步解释。任何帮助将不胜感激。
到目前为止,请参阅脚本:
//@version=4
study("Highest Test Script", overlay=true)
offset_val = input(title="Daily Label Offset", type=input.integer, defval=10)
offset_valW = input(title="Weekly Label Offset", type=input.integer, defval=30)
// Asia Start
time_int_01 = input("0000-0100:1234567", "Asia", input.session)
in_time_int_01 = time(timeframe.period, time_int_01)
var highe_01 = 0.0
var lowe_01 = 10e10
if in_time_int_01
if not in_time_int_01[1]
highe_01 := high
lowe_01 := low
else
highe_01 := max(high, highe_01)
lowe_01 := min(low, lowe_01)
plot(not in_time_int_01 ? highe_01 : na, title="Asia High", color=color.purple, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_01 ? highe_01 : na, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="Asia/UTC High", offset = offset_val, transp=20, title="Asia/UTC High")
plot(not in_time_int_01 ? lowe_01 : na, title="Asia Low", color=color.purple, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_01 ? lowe_01 : na, style=shape.labeldown, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="Asia/UTC Low", offset = offset_val, transp=20, title="Asia/UTC Low")
// Asia Finish
// London Start
time_int_02 = input("0800-0900:1234567", "London", input.session)
time_int_002 = input("0900-0800:1234567", "London", input.session)
in_time_int_02 = time(timeframe.period, time_int_02)
var highe_02 = 0.0
var lowe_02 = 10e10
if in_time_int_02
if not in_time_int_02[1]
highe_02 := high
lowe_02 := low
else
highe_02 := max(high, highe_02)
lowe_02 := min(low, lowe_02)
plot(not in_time_int_02 ? highe_02 : na, title="London High", color=color.yellow, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_02 ? highe_02 : na, style=shape.labelup, location=location.absolute, color=color.yellow, textcolor=color.white, show_last=1, text="London High", offset = offset_val, transp=20, title="London High")
plot(not in_time_int_02 ? lowe_02 : na, title="London Low", color=color.yellow, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_02 ? lowe_02 : na, style=shape.labeldown, location=location.absolute, color=color.yellow, textcolor=color.white, show_last=1, text="London Low", offset = offset_val, transp=20, title="London Low")
// London Finsh
// New York Start
time_int_03 = input("1430-1530:1234567", "New York", input.session)
in_time_int_03 = time(timeframe.period, time_int_03)
var highe_03 = 0.0
var lowe_03 = 10e10
if in_time_int_03
if not in_time_int_03[1]
highe_03 := high
lowe_03 := low
else
highe_03 := max(high, highe_03)
lowe_03 := min(low, lowe_03)
plot(not in_time_int_03 ? highe_03 : na, title="New York High", color=color.blue, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_03 ? highe_03 : na, style=shape.labelup, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="New York High", offset = offset_val, transp=20, title="New York High")
plot(not in_time_int_03 ? lowe_03 : na, title="New York Low", color=color.blue, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_03 ? lowe_03 : na, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="New York Low", offset = offset_val, transp=20, title="New York Low")
// New York Finish
//Londontest = (not time_int_002 ? highe_02 : na)
//DailyIBHighest = max(highe_01, Londontest, highe_03)
DailyIBHighest = max(highe_01, highe_02, highe_03)
plot(DailyIBHighest, color=color.white, linewidth=1, style=plot.style_linebr)
#####更新 18/02/2021 @ 1600 #####
在进一步考虑了这个问题之后,我想要实现的是计算出最大 IB 高,如下所述:
0000 - 0100
黄色 - highe_02
蓝色 - highe_03
0100 - 0800
黄色 - highe_02
蓝色 - highe_03
紫色 - highe_01
0800 - 0900
蓝色 - highe_03
紫色 - highe_01
0900 - 1430
黄色 - highe_02
蓝色 - highe_03
紫色 - highe_01
1430 - 1530
黄色 - highe_02
紫色 - highe_01
1530 - 0000
黄色 - highe_02
蓝色 - highe_03
紫色 - highe_01
##### 更新 19/02/2021 @ 0845 ####
我已将原始 IB 设置为高/低,因为可以打开设置中的错误以确认红线正确对齐。这就是我希望它显示的方式,但我觉得我没有采取正确的方式,因为我想将输出红线合并到一个输出中,以便我可以将它用于警报。
//@version=4
study("Highest Test Script", overlay=true)
offset_val = input(title="Daily Label Offset", type=input.integer, defval=10)
offset_valW = input(title="Weekly Label Offset", type=input.integer, defval=30)
ShowIB = input(false, title="show IBs")
// Asia Start
time_int_01 = input("0000-0100:1234567", "Asia", input.session)
time_int_001 = input("0100-0000:1234567", "London", input.session)
in_time_int_01 = time(timeframe.period, time_int_01)
in_time_int_001 = time(timeframe.period, time_int_001)
var highe_01 = 0.0
var lowe_01 = 10e10
if in_time_int_01
if not in_time_int_01[1]
highe_01 := high
lowe_01 := low
else
highe_01 := max(high, highe_01)
lowe_01 := min(low, lowe_01)
plot(not in_time_int_01 and ShowIB ? highe_01 : na, title="Asia High", color=color.purple, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_01 and ShowIB ? highe_01 : na, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="Asia/UTC High", offset = offset_val, transp=20, title="Asia/UTC High")
plot(not in_time_int_01 and ShowIB ? lowe_01 : na, title="Asia Low", color=color.purple, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_01 and ShowIB ? lowe_01 : na, style=shape.labeldown, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="Asia/UTC Low", offset = offset_val, transp=20, title="Asia/UTC Low")
// Asia Finish
// London Start
time_int_02 = input("0800-0900:1234567", "London", input.session)
time_int_002 = input("0900-0800:1234567", "London", input.session)
in_time_int_02 = time(timeframe.period, time_int_02)
in_time_int_002 = time(timeframe.period, time_int_002)
var highe_02 = 0.0
var lowe_02 = 10e10
if in_time_int_02
if not in_time_int_02[1]
highe_02 := high
lowe_02 := low
else
highe_02 := max(high, highe_02)
lowe_02 := min(low, lowe_02)
plot(not in_time_int_02 and ShowIB ? highe_02 : na, title="London High", color=color.yellow, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_02 and ShowIB ? highe_02 : na, style=shape.labelup, location=location.absolute, color=color.yellow, textcolor=color.white, show_last=1, text="London High", offset = offset_val, transp=20, title="London High")
plot(not in_time_int_02 and ShowIB ? lowe_02 : na, title="London Low", color=color.yellow, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_02 and ShowIB ? lowe_02 : na, style=shape.labeldown, location=location.absolute, color=color.yellow, textcolor=color.white, show_last=1, text="London Low", offset = offset_val, transp=20, title="London Low")
// London Finsh
// New York Start
time_int_03 = input("1430-1530:1234567", "New York", input.session)
time_int_003 = input("1530-1430:1234567", "New York", input.session)
in_time_int_03 = time(timeframe.period, time_int_03)
in_time_int_003 = time(timeframe.period, time_int_003)
var highe_03 = 0.0
var lowe_03 = 10e10
if in_time_int_03
if not in_time_int_03[1]
highe_03 := high
lowe_03 := low
else
highe_03 := max(high, highe_03)
lowe_03 := min(low, lowe_03)
plot(not in_time_int_03 and ShowIB ? highe_03 : na, title="New York High", color=color.blue, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_03 and ShowIB ? highe_03 : na, style=shape.labelup, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="New York High", offset = offset_val, transp=20, title="New York High")
plot(not in_time_int_03 and ShowIB ? lowe_03 : na, title="New York Low", color=color.blue, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_03 and ShowIB ? lowe_03 : na, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="New York Low", offset = offset_val, transp=20, title="New York Low")
// New York Finish
Session01 = input("0000-0100:1234567", "0000 - 0100", input.session)
S1 = time(timeframe.period, Session01)
Session02 = input("0100-0800:1234567", "0100 - 0800", input.session)
S2 = time(timeframe.period, Session02)
Session03 = input("0800-0900:1234567", "0800 - 0900", input.session)
S3 = time(timeframe.period, Session03)
Session04 = input("0900-1430:1234567", "0900 - 1430", input.session)
S4 = time(timeframe.period, Session04)
Session05 = input("1430-1530:1234567", "1430 - 1530", input.session)
S5 = time(timeframe.period, Session05)
Session06 = input("1530-0000:1234567", "1530 - 0000", input.session)
S6 = time(timeframe.period, Session06)
Test1 = S2 or S4 or S6 ? max(highe_01, highe_02, highe_03) : na
Test2 = S5 ? max(highe_02, highe_01) : na
Test3 = S1 ? max(highe_02, highe_03) : na
Test4 = S3 ? max(highe_03, highe_01) : na
Test1a = S2 or S4 or S6 ? min(lowe_01, lowe_02, lowe_03) : na
Test2a = S5 ? min(lowe_02, lowe_01) : na
Test3a = S1 ? min(lowe_02, lowe_03) : na
Test4a = S3 ? min(lowe_03, lowe_01) : na
plot(Test1, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test2, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test3, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test4, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test1a, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test2a, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test3a, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test4a, color=color.red, linewidth=1, style=plot.style_linebr)
有没有办法将以下提取物放入 var 或函数中?只是似乎代码很多,我觉得我没有正确完成它。
Session01 = input("0000-0100:1234567", "0000 - 0100", input.session)
S1 = time(timeframe.period, Session01)
Session02 = input("0100-0800:1234567", "0100 - 0800", input.session)
S2 = time(timeframe.period, Session02)
Session03 = input("0800-0900:1234567", "0800 - 0900", input.session)
S3 = time(timeframe.period, Session03)
Session04 = input("0900-1430:1234567", "0900 - 1430", input.session)
S4 = time(timeframe.period, Session04)
Session05 = input("1430-1530:1234567", "1430 - 1530", input.session)
S5 = time(timeframe.period, Session05)
Session06 = input("1530-0000:1234567", "1530 - 0000", input.session)
S6 = time(timeframe.period, Session06)
Test1 = S2 or S4 or S6 ? max(highe_01, highe_02, highe_03) : na
Test2 = S5 ? max(highe_02, highe_01) : na
Test3 = S1 ? max(highe_02, highe_03) : na
Test4 = S3 ? max(highe_03, highe_01) : na
Test1a = S2 or S4 or S6 ? min(lowe_01, lowe_02, lowe_03) : na
Test2a = S5 ? min(lowe_02, lowe_01) : na
Test3a = S1 ? min(lowe_02, lowe_03) : na
Test4a = S3 ? min(lowe_03, lowe_01) : na
plot(Test1, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test2, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test3, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test4, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test1a, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test2a, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test3a, color=color.red, linewidth=1, style=plot.style_linebr)
plot(Test4a, color=color.red, linewidth=1, style=plot.style_linebr)
解决方案
我希望这次我没看错。只有我的设计显示一条黑线而不是一条白线。
//@version=4
study("Help (Highest Test Script)", overlay=true)
offset_val = input(title="Daily Label Offset", type=input.integer, defval=10)
offset_valW = input(title="Weekly Label Offset", type=input.integer, defval=30)
// Asia Start
time_int_01 = input("0000-0100:1234567", "Asia", input.session)
in_time_int_01 = time(timeframe.period, time_int_01)
// London Start
time_int_02 = input("0800-0900:1234567", "London", input.session)
time_int_002 = input("0900-0800:1234567", "London", input.session)
in_time_int_02 = time(timeframe.period, time_int_02)
// New York Start
time_int_03 = input("1430-1530:1234567", "New York", input.session)
in_time_int_03 = time(timeframe.period, time_int_03)
// Asia Start
var highe_01 = 0.0
var lowe_01 = 10e10
if in_time_int_01
if not in_time_int_01[1]
highe_01 := high
lowe_01 := low
else
highe_01 := max(high, highe_01)
lowe_01 := min(low, lowe_01)
plot(not in_time_int_01 and not in_time_int_02 and not in_time_int_03 ? highe_01 : na, title="Asia High", color=color.purple, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_01 ? highe_01 : na, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="Asia/UTC High", offset = offset_val, transp=20, title="Asia/UTC High")
plot(not in_time_int_01 and not in_time_int_02 and not in_time_int_03 ? lowe_01 : na, title="Asia Low", color=color.purple, linewidth=2, style=plot.style_linebr)
plotshape(not in_time_int_01 ? lowe_01 : na, style=shape.labeldown, location=location.absolute, color=color.purple, textcolor=color.white, show_last=1, text="Asia/UTC Low", offset = offset_val, transp=20, title="Asia/UTC Low")
// Asia Finish
// London Start
var highe_02 = 0.0
var lowe_02 = 10e10
if in_time_int_02
if not in_time_int_02[1]
highe_02 := high
lowe_02 := low
else
highe_02 := max(high, highe_02)
lowe_02 := min(low, lowe_02)
plot(not in_time_int_01 and not in_time_int_02 and not in_time_int_03 ? highe_02 : na, title="London High", color=color.yellow, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_02 ? highe_02 : na, style=shape.labelup, location=location.absolute, color=color.yellow, textcolor=color.white, show_last=1, text="London High", offset = offset_val, transp=20, title="London High")
plot(not in_time_int_01 and not in_time_int_02 and not in_time_int_03 ? lowe_02 : na, title="London Low", color=color.yellow, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_02 ? lowe_02 : na, style=shape.labeldown, location=location.absolute, color=color.yellow, textcolor=color.white, show_last=1, text="London Low", offset = offset_val, transp=20, title="London Low")
// London Finsh
// New York Start
var highe_03 = 0.0
var lowe_03 = 10e10
if in_time_int_03
if not in_time_int_03[1]
highe_03 := high
lowe_03 := low
else
highe_03 := max(high, highe_03)
lowe_03 := min(low, lowe_03)
plot(not in_time_int_01 and not in_time_int_02 and not in_time_int_03 ? highe_03 : na, title="New York High", color=color.blue, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_03 ? highe_03 : na, style=shape.labelup, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="New York High", offset = offset_val, transp=20, title="New York High")
plot(not in_time_int_01 and not in_time_int_02 and not in_time_int_03 ? lowe_03 : na, title="New York Low", color=color.blue, linewidth=3, style=plot.style_linebr)
plotshape(not in_time_int_03 ? lowe_03 : na, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="New York Low", offset = offset_val, transp=20, title="New York Low")
// New York Finish
//Londontest = (not time_int_002 ? highe_02 : na)
//DailyIBHighest = max(highe_01, Londontest, highe_03)
DailyIBHighest = max(highe_01, highe_02, highe_03)
plot(DailyIBHighest, color=color.white, linewidth=1, style=plot.style_linebr)
推荐阅读
- node.js - 使用 Multer 上传文件时显示进度
- sql - 从 SQL 表中的 JSON 列中检索数据
- c++ - 正方体初始化失败
- datetime - 如何在不使用 date_trunc 函数的情况下从 PostgreSQL 中的列(时间戳)中截断秒数
- sqlite - 从 SQLite 读取一个数据到 Unity 没有 where 编码
- angular - 错误类型错误:无法读取未定义的属性“openDialogTEST”
- angular - Angular 6 无限循环并等待 API 响应
- azure - 在受 Azure Ad OAuth 保护的 api 中看不到范围声明
- angular5 - 如何使用 Angular 5 HttpClient 读取完整的响应标头
- windows - Powershell 一直问我同样的问题