Please tell me how to calculate the highest price and the lowest price in the historical range. Thank you.
indicator("计算历史区间最高价、最低价", overlay=true)
//目的:想在开单时,找出开单前(输入历史长度)的最高价,或最低价,用于计算开单止损价。
varip ishistory_high_Price0 = array.new_float(0) //定义变量,初始化历史高价格为空的数组
varip ishistory_low_Price0 = array.new_float(0) //定义变量,初始化历史低价格为空的数组
var ishistory_length = input.int(15, minval=1, maxval=100, step=1) //定义变量,历史长度,输入为15,最小值1,最大值100,步长1
var ishistory_high_Price = na
var ishistory_low_Price = na
if barstate.ishistory //对历史K线执行计算(not barstate.ishistory当在实时abr时在执行)
array.push(ishistory_high_Price0, nz(high[1], open)) //写入数组(变量ishistory_high_Price0的历史最高价元素,空值用开盘价)
if array.size(ishistory_high_Price0) > ishistory_length //当数组的长度大于变量长度的时候
array.shift(ishistory_high_Price0) //删除数组(ishistory_high_Price0的第一个元素)
[ishistory_high_Price0]
if barstate.ishistory //对历史K线执行计算
array.push(ishistory_low_Price0, nz(low[1], open)) //写入数组(变量ishistory_low_Price0的历史最低价元素,空值用开盘价)
if array.size(ishistory_low_Price0) > ishistory_length //当数组的长度大于变量长度的时候
array.shift(ishistory_low_Price0) //删除数组(ishistory_low_Price0的第一个元素)
[ishistory_low_Price0]
//需对历史高价格、历史低价格作出比较,并返回最大值(输入周期内的历史最高价、历史最低价)
//下面这个写法不正确!!!
ishistory_high_Price = array.max(ishistory_high_Price0, nz(high[1], open), ishistory_length)
ishistory_low_Price = array.min(ishistory_low_Price0, nz(low[1], open),ishistory_length)
plot(title = "数组ishistory_high_Price中的历史高价格:", ishistory_high_Price, color = color.blue)
plot(title = "数组ishistory_low_Price中的历史低价格:", ishistory_low_Price, color = color.red)
Although I have learned the introductory tutorial of the PINE language, the sum of an array or the size of the element in the array can be used, but it is not possible to rewrite the history of the K-string! Please guide me on the definition of the variable, and compare it with the historical high price, historical low price, historical high price and historical low price, thank you.
hopeNo problem, after printing the graph to the attached graph, the thesis is displayed normally.
hopeWell, thank you very much, this is the changed code: '" indicator (("calculate the highest price, the lowest price in the historical range") // Purpose: When opening an order, find the highest price before opening the order (input historical length), or the lowest price, to calculate the single stop loss price. var ishistory_length = input.int(15, title = "ishistory length", minval=1, maxval=100, step=1) // define variable, history length, input is 15, minimum 1, maximum 100, step length 1 - What? var float highest = na // the highest value of a given number past k lines. var float lowest = na // lowest value of a given number of k lines past it. var float highestbars = na // The maximum value deviation of a given number of k lines past it. var float lowestbars = na // The minimum value deviation of a given number of k lines past it. highest := ta.highest ((high, ishistory_length) // Resets the maximum value of the history K string length to 15. plot ((highest, title = "Highest price in historical K line:", color = color.blue, overlay=true) lowest := ta.lowest ((low, ishistory_length) // Reset the minimum value of the length of the history K line to 15. plot ((lowest, title = "lowest price in historical K line:", color = color.red, overlay=true) highest:= ta.highest ((high[1], ishistory_length) // Resets the maximum value of the length of the history K string to 15. plot ((highest, title = "Highest price in historical K line:", color = color.blue, overlay=true) lowest := ta.lowest ((low[1], ishistory_length) // Resets the minimum value of the length of the history K line to 15. plot ((lowest, title = "lowest price in historical K line:", color = color.red, overlay=true) The printing of the deviation below shows a bit of a problem and I don't know how to change it. highestbars := ta.highestbars ((high, ishistory_length) // Reassigns the maximum value deviation of the length of the historical K-line to 15. plot ((highestbars, title = "High price deviation in historical K line:", color = color.orange, overlay = true) lowestbars := ta.lowestbars ((low, ishistory_length) // Minimum value deviation of a given number of lines past k. plot ((lowestbars, title = "Low price deviation in historical K line:", color = color.white, overlay=true) '" There are also three small questions to learn: 1, as long as the built-in pine function that is being called asks for the highest or lowest value in the history, in the code, such as high, and high[1], they all get the same result, right? If I need to call these values later in the policy, I can use either the highest or lowest values directly in the policy conditions, right? 3, the offset print above shows a bit of a problem and I don't know how to change it.
Inventors quantify - small dreamsThe maximum and minimum value of a data series in a given range, with built-in functions that are directly applicable: What's up? ta.highest ((source, length)) ta.lowest ((source, length)) What's up? For example, the maximum closing price in the range of the current 10 K-line BARs is required: What's up? highest10 = ta.highest ((close, 10) What's up?
Inventors quantify - small dreams OK
Inventors quantify - small dreams1, high, and high[1] are definitely not the same,[] are historical operation references, which refer to snapshot data on the previous BAR. 2, you can calculate a value and record it with a variable. 3⁄4 Describe the specific problem, run the test, no problem.