我一直在嘗試用 pine 腳本撰寫我的第一個代碼。問題是這個。我創建了幾個 array.new_float 用作“for”陳述句中的緩沖區。問題是我需要對資料進行一些數學運算。現在,一旦 'for' 完成,就會彈出一個錯誤:'Cannot call 'operator -' with argument 'expr0' = 'High'。使用了 'float[]' 型別的引數,但需要一個 'const int' '。
請,如果有人知道我做錯了什么,我會感謝你。
編輯:我將在此處保留我要執行的操作的腳本
//@version=5
// Indicator name
indicator("DAF_Swing_Index", shorttitle= 'DAF_SwInd', overlay=false)
// Input
T = input.int(30000, title = 'Ratio de escala', minval = 1000, maxval = 150000)
Shift = input.int(0, title = 'Desplazamiento horizontal', minval = 0, maxval = 100)
// Array
SWINGINDEX = array.new_float(200)
Open = array.new_float(200)
Open1 = array.new_float(200)
Close = array.new_float(200)
Close1 = array.new_float(200)
High = array.new_float(200)
Low = array.new_float(200)
// Other variable
var float SwingIndex = 0
var int StartBars = 1
Prev_calculated = bar_index
Rates_total = bar_index 1
var float SH1 = 0
var float SI = 0
var float R = 0
// Initial bar verification
if Rates_total < StartBars
SwingIndex := 0
Primero = 1
if Prev_calculated > Rates_total or Prev_calculated <= 0
Primero := 1
else
Primero := Prev_calculated-1
// Main process
for bar = Primero to Rates_total
array.push(Open, high[bar])
array.push(Open1, open[bar-1])
array.push(Close, close[bar])
array.push(Close1, close[bar-1])
array.push(High, high[bar])
array.push(Low, low[bar])
K = math.max(math.abs(High - Close1), math.abs(Low - Close1))
TR = math.max(math.max(math.abs(High-Close1), math.abs(Low-Close1)), math.abs(High-Low))
ER = 0.0
if Close1 > High
ER := math.abs(High - Close1)
if Close1 < Low
ER := math.abs(Low - Close1)
SH1 := math.abs(Close1 - Open1)
R := TR - 0.5 * ER 0.25 * SH1
SI := 0.0
if R != 0
SI := 50 * ((Close - Close1) 0.5 * (Close - Open1)) * (K / T) / R
SwingIndex := SI
// ploting result
plot(SwingIndex, title = 'Swing Index', style = plot.style_line, color = color.rgb(193, 255, 51, 10))
uj5u.com熱心網友回復:
因此,錯誤訊息告訴您的是,您正在傳遞一個陣列,它需要一個 const 值。
像這兒:
K = math.max(math.abs(High - Close1), math.abs(Low - Close1))
所有這些變數 ( High, Close1, Low) 都是陣列。它根本無法從另一個陣列中減去一個陣列。但是,您可以從另一個元素中減去一個元素。
所以對于那條線,我相信你想要這樣的東西:
K = math.max(math.abs(array.get(High, bar) - array.get(Close1, bar)), math.abs(array.get(Low, bar) - array.get(Close1, bar)))
使用array.get(),您可以獲得指定索引處元素的值。
您應該在所有其他情況下解決此問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/343360.html
上一篇:Javascript無法正確計算xorshiftmult。如何使它作業?
下一篇:折扣率、公式
