tyforcode
tyforcode

Reputation: 1767

Variable 'target' was declared with 'integer' type. Cannot assign it expression of type 'series[float]'

I'm looking to get the single highest value for the previous 5 bars of data but keep running into the posted error: Variable 'target' was declared with 'integer' type. Cannot assign it expression of type 'series[float]'.

Here are the 2 lines of code in question:

var target = 0
target := highest(high, 5)[0]

I would assume this would retrieve the latest highest value but it instead returns a series. Please let me know the correct way of achieving this.

Upvotes: 1

Views: 1833

Answers (1)

Bjorgum
Bjorgum

Reputation: 2310

Try adding a .0 after var target. The highest function is looking for a float variable.

var target = 0.0

Alternately we could forgo using var at all here and just say = highest().

Also we do not need [0] as that references this bar which it will do anyway. We can place 1 or more in there to reference one bar back etc.

Cheers my friend and best of luck with your trading and coding

Upvotes: 2

Related Questions