最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Pine Script Request Security returning unexpected values - Stack Overflow

programmeradmin2浏览0评论

I have used the request.security feature a lot in the past but somehow today it is giving me a hard time and a script working perfectly yesterday evening is no longer working today. I have reduced the script to the bare minimum and I noticed, that request.security is not returning the values expected for the given timeframe, but instead is influenced by the Charts timeframe.

In this small test script I want to read out the monthly high of the previous months. From my understanding this script should work on every chart and changing the chart resolution should not influence the output of the script - but it does. Only if I select a monthly timeframe on the Chart I get the correct monthly highs of the previous 3 months.

//@version=6
indicator("Test Request Sec", overlay = true)

// Request monthly highs
testHigh = request.security(symbol = syminfo.tickerid, timeframe = "1M", expression = high)

// Create a small table for debugging output
testTable = table.new(position=position.top_right, columns=1, rows=3)

// Write the last three values of the monthly highs into the table. This is only giving the correct values if the Chart is set to 1M as well.
table.cell(table_id = testTable, column = 0, row =  0, text=str.tostring(testHigh[1]), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  1, text=str.tostring(testHigh[2]), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  2, text=str.tostring(testHigh[3]), text_color = color.white)

As of today, for AAPL I would expect $249.10, $260.10 and $237.81 but every other chart timeframe apart 1M is returning something else.

Any feedback would be highly appreciated!

I have used the request.security feature a lot in the past but somehow today it is giving me a hard time and a script working perfectly yesterday evening is no longer working today. I have reduced the script to the bare minimum and I noticed, that request.security is not returning the values expected for the given timeframe, but instead is influenced by the Charts timeframe.

In this small test script I want to read out the monthly high of the previous months. From my understanding this script should work on every chart and changing the chart resolution should not influence the output of the script - but it does. Only if I select a monthly timeframe on the Chart I get the correct monthly highs of the previous 3 months.

//@version=6
indicator("Test Request Sec", overlay = true)

// Request monthly highs
testHigh = request.security(symbol = syminfo.tickerid, timeframe = "1M", expression = high)

// Create a small table for debugging output
testTable = table.new(position=position.top_right, columns=1, rows=3)

// Write the last three values of the monthly highs into the table. This is only giving the correct values if the Chart is set to 1M as well.
table.cell(table_id = testTable, column = 0, row =  0, text=str.tostring(testHigh[1]), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  1, text=str.tostring(testHigh[2]), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  2, text=str.tostring(testHigh[3]), text_color = color.white)

As of today, for AAPL I would expect $249.10, $260.10 and $237.81 but every other chart timeframe apart 1M is returning something else.

Any feedback would be highly appreciated!

Share Improve this question asked Feb 7 at 14:35 KsSoKsSo 11 bronze badge New contributor KsSo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 2
  • With testHigh[1] you will have the value of the previous candle, not the previous month. – Gu5tavo71 Commented Feb 7 at 18:01
  • 1 Darn it, of course... Thanks for the little nudge. This is what my brain needed. – KsSo Commented Feb 8 at 9:47
Add a comment  | 

1 Answer 1

Reset to default 1

The code from your snippet prints the previous month high of the last three bars of your chart:

testHigh = request.security(symbol = syminfo.tickerid, timeframe = "1M", expression = high)

// ...

table.cell(table_id = testTable, column = 0, row =  0, text=str.tostring(testHigh[1]), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  1, text=str.tostring(testHigh[2]), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  2, text=str.tostring(testHigh[3]), text_color = color.white)

The following snippet prints the three previous months highs of the last bar of your chart:

[prevHigh1, prevHigh2, prevHigh3] = request.security(symbol = syminfo.tickerid, timeframe = "1M", expression = [high, high[1], high[2]])

//...

table.cell(table_id = testTable, column = 0, row =  0, text=str.tostring(prevHigh1), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  1, text=str.tostring(prevHigh2), text_color = color.white)
table.cell(table_id = testTable, column = 0, row =  2, text=str.tostring(prevHigh3), text_color = color.white)
发布评论

评论列表(0)

  1. 暂无评论