这是我的代码。我试图在柱线关闭时获得更高的时间范围数据,以便我做出交易决定。但由于某种原因,它滞后了。我首先在较短的时间范围内对其进行测试,看看它是否有效。我将脚本添加到 1m 图表并从 5m 图表中获取数据,但由于某种原因,它没有立即获得最新的 5m 柱收盘信息。我究竟做错了什么?我只是出于调试目的在图表上打印值。
// 此源代码受 Mozilla Public License 2.0 条款的约束,网址为https://mozilla.org/MPL/2.0/
//@version=5 strategy("HTF 数据", overlay=true)
HTF = "5"
HTFClose = request.security(syminfo.tickerid, HTF, close[1], gaps = barmerge.gaps_off, lookahead=barmerge.lookahead_on) HTFClose2 = request.security(syminfo.tickerid, HTF, close[2], gaps = barmerge. gaps_off,lookahead=barmerge.lookahead_on)
// MA HTFEMA1 = request.security(syminfo.tickerid, HTF, ta.ema(close[1], 8), gaps = barmerge.gaps_off, lookahead=barmerge.lookahead_on) HTFEMA2 = request.security(syminfo.tickerid, HTF , ta.ema(close[2], 8), gaps = barmerge.gaps_off, lookahead=barmerge.lookahead_on)
// MACD, Signal 和 Hist [macdLineD, signalLineD, histLineD] = request.security(syminfo.tickerid, HTF, ta.macd(close[1], 8, 21, 9), gaps = barmerge.gaps_off, lookahead=barmerge .lookahead_on)
var testTable = table.new(position = position.top_right, columns = 1, rows = 7, bgcolor = color.yellow, border_width = 1) if barstate.islast table.cell(table_id = testTable, column = 0, row = 0 , text = "HTFClose:" + str.tostring(HTFClose)) table.cell(table_id = testTable, column = 0, row = 1, text = "HTFClose2:" + str.tostring(HTFClose2), bgcolor=color.white ) table.cell(table_id = testTable, column = 0, row = 2, text = "HTFEMA1:" + str.tostring(HTFEMA1)) table.cell(table_id = testTable, column = 0, row = 3, text = " HTFEMA2: " + str.tostring(HTFEMA2), bgcolor=color.white) table.cell(table_id = testTable, column = 0, row = 4, text = "macdLineD: " + str.tostring(macdLineD), bgcolor=color .red )
table.cell(table_id = testTable, column = 0, row = 5, text = "signalLineD:"+ str.tostring(signalLineD), bgcolor=color.white)
table.cell(table_id = testTable, column = 0, row = 6, text = "histLineD:" + str.tostring(histLineD))