I have an error in my code that does not let me add the indicator to the chart, the following message appears in the console '
Error at 20:22 Mismatched input 'end of line without line continuation' expecting ')'
this problem is in this specific part Of code:
myLabel := label.new(
x=bar_index,
y=high,
text="NPL: " + tostring(npl),
yloc=yloc.abovebar,
color=color.green,
textcolor=color.white,
style=label.style_label_left
)
I will also attach an image so that you understand the problem in depth:
the complete code below:
//@version=5
indicator("NPL Calculator v3", overlay=false)
// Inputs
percent = input.float(title="Percentage", defval=20.0, step=0.01) / 100
leverage = input.float(title="Leverage", defval=10.0, step=0.01)
money = input.float(title="Money", defval=100.0, step=0.01)
// Calculations
npl = money * percent * leverage
// Plots
plot(npl, title="NPL", color=color.blue, style=plot.style_line)
// Labels
var label myLabel = na
if not na(myLabel)
label.delete(myLabel)
myLabel := label.new(
x=bar_index,
y=high,
text="NPL: " + tostring(npl),
yloc=yloc.abovebar,
color=color.green,
textcolor=color.white,
style=label.style_label_left
)
// Alert
alertcondition(npl > 0, title="NPL Alert", message="NPL: " + tostring(npl))
// Backtesting
strategy.entry("NPL Buy", strategy.long, when=npl > 0)
strategy.close("NPL Buy", when=npl <= 0)
Any idea how to fix it?
fix this part of the code mentioned above
In pinescript the indentation for local block is 4 spaces and you musn't use it elsewhere.
You should indent you line.new code with 3 spaces (or 2, or 5, but not with 4 spaces), like this :
myLabel := label.new(
x=bar_index,
y=high,
text="NPL: " + str.tostring(npl),
yloc=yloc.abovebar,
color=color.green,
textcolor=color.white,
style=label.style_label_left)
NB : There are other error in your code, do not hesitate to ask a new question with your new code if you can't solve them.