Tolong tunjukkan kepada saya cara betul untuk mengira harga tertinggi dan terendah dalam tempoh sejarah.
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)
Walaupun anda telah mempelajari tutorial permulaan dalam bahasa PINE, penjumlahan atau elemen dalam array yang lebih besar dan lebih kecil boleh digunakan secara serentak, tetapi anda tidak boleh menulis semula dengan menukarnya kepada garis K sejarah! Mohon bimbingannya dalam menentukan variabel dan membandingkannya dengan harga tinggi dan rendah bersejarah, terima kasih.