-2

Every time I tried to run the code I got this message.

10:32:09 PM Error at 4:37 Undeclared identifier 'input.'
10:32:09 PM Error at 4:32 The 'input' function does not have an argument with the name 'type'
10:32:09 PM Error at 6:5 Could not find function or function reference 'highest'

this is the full code

"//@version=5
indicator("Flag Pattern", shorttitle="Flag Pattern", overlay=true)

length = input(title="Length", type=input.integer, defval=10)

h = highest(high, length)
l = lowest(low, length)
price_range = h - l

flag_height = price_range * 2
flag_width = rma(tr, length) * 2

flagpole_start_x = length - 1
flagpole_start_y = l
flagpole_end_x = length - 1
flagpole_end_y = h

flag_start_x = flagpole_end_x + 1
flag_start_y = flagpole_end_y
flag_end_x = flag_start_x + flag_width
flag_end_y = flag_start_y + flag_height

line.new(x1=flagpole_start_x, y1=flagpole_start_y, x2=flagpole_end_x, y2=flagpole_end_y, color=color.white, width=1)
linebr = line.new(x1=flag_start_x, y1=flag_start_y, x2=flag_end_x, y2=flag_end_y, color=color.white, width=1)
line.new(x1=flag_start_x, y1=flagpole_start_y, x2=flagpole_end_x, y2=flagpole_start_y, color=color.white, width=1)
line.new(x1=flag_end_x, y1=flagpole_end_y, x2=flagpole_end_x, y2=flag_start_y, color=color.white, width=1)

flag_high = valuewhen(crossunder(low, l, 1), high, 0)
flag_low = valuewhen(crossover(high, h, 1), low, 0)

is_flag = flag_high > 0 and flag_low > 0 and flag_high > flag_low and flag_high - flag_low > price_range

bgcolor(is_flag ? color.green : na, transp=80)"

how to find out what the issue is and how to solve it?

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

This code is written in v4 and not in v5.

So, change your indicator() call to study().

You are also passing a float to your line.new()'s x1 and x2 arguments which will not work. You may try casting them to int with int().

Lastly, your use of crossover() and crossunder() are wrong. Those functions take two parameters.

crossover(x, y) → series[bool]

RETURNS
true if x crossed over y otherwise false
ARGUMENTS
x (float) Data series x.
y (float) Data series y.

vitruvius
  • 15,740
  • 3
  • 16
  • 26