KU8E
KU8E

Reputation: 1

Pinescript code indicator errors, may need updating to pinescript v5 but unsure

Extremely new to coding in all senses and trying to combine a zlsma indicator with a macd indicator to give buy and sell signals when the indicators cross each other. had some problems at first but noticed that pinescript v5 had changed the input functions and tried a few different ones which fixed some code but left some errors. code throws the error "The 'input' function does not have an argument with the name 'type'" and the error appears in all location that contain "type=input.int". not sure if I need to remove "type" in some way or rewrite it differently

farthest I was able to get was taking "type=" completely out of all the lines that contained it but was left with syntax errors. code is as follows:

//@version=5
indicator("My script")
plot(close)

// Inputs
length = input(title="Length", type=input.int, defval=32)
offset = input(title="Offset", type=input.int, defval=0)
src = close

// ZLSMA Indicator
lsma = ta.linreg(src, length, offset)
lsma2 = ta.linreg(lsma, length, offset)
eq = lsma - lsma2
zlsma = lsma + eq

// MACD Indicator
fast_length = input(title="Fast Length", type=input.int, defval=12)
slow_length = input(title="Slow Length", type=input.int, defval=26)
signal_length = input(title="Signal Length", type=input.int, defval=9)
macd = ta.ema(src, fast_length) - ta.ema(src, slow_length)
macd_signal = ta.sma(macd, signal_length)

// Buy and Sell Signals
buy = crossover(zlsma, 0) and macd > macd_signal
sell = crossover(0, zlsma) and macd < macd_signal

// Plotting
plot(zlsma, color=color.yellow, linewidth=3)
plot(0, color=color.gray, linewidth=1)
plot(macd, color=color.blue, linewidth=1)
plot(macd_signal, color=color.red, linewidth=1)
plotshape(buy, color=color.green, style=shape.arrowup)
plotshape(sell, color=color.red, style=shape.arrowdown)

Upvotes: 0

Views: 459

Answers (1)

vitruvius
vitruvius

Reputation: 21342

The error message tells you what is wrong.

The input function does not have an qrgument named "type" but it is there in your code.

length = input(title="Length", type=input.int, defval=32)

You see that type=input.int there?

In v5, you would write this as:

length = input.int(title="Length", defval=32)

See this for the list of other input functions.

Upvotes: 0

Related Questions