2
Подписаться
0
Подписчики

Пожалуйста, подскажите мне, как правильно написать «рассчитать самые высокие и самые низкие цены в историческом диапазоне», спасибо.

Создано: 2022-10-17 00:13:14, Обновлено: 2022-10-17 15:28:07
comments   5
hits   962

Пожалуйста, научите меня правильно записывать максимумы и минимумы за исторический период.

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)

Хотя введение в язык ПИНЭ позволяет использовать множители или элементы в массивах по сравнению с более крупными элементами, переписывать историческую K-линию невозможно! Пожалуйста, помогите нам определить переменные и сравнить их с историческими высокими и историческими низкими ценами.