Reputation: 1
i try to code my first pinescript and i'm stuck: Why does this not run?
I want do draw a dot when two lines cross up or cross down. I want see the green dots only, when the crossdown is above the zero-line and i only want see the red dots, when crossup is below the zero-line. x1 ist crossover and x2 is crossunder. x1 and x2 was delcared in the code further up in the script.
if x1 > 0
plot(x1 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')
if x2 < 0
plot(x2 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')
When i use the code without the if-comand then the dots were shown. So i think the problem have to do woth the if-command.
I've got this errors:
line 67: Cannot call 'operator >' with argument 'expr0'='x1'. An argument of 'series bool' type was used but a 'const float' is expected;
line 68: Cannot use 'plot' in local scope.;
line 70: Cannot call 'operator <' with argument 'expr0'='x2'. An argument of 'series bool' type was used but a 'const float' is expected;
line 71: Cannot use 'plot' in local scope.
Can you please help me to solve this problem?
Thanks a lot!!!
Upvotes: 0
Views: 148
Reputation: 1
First of all, thank you for your support. For me as a newbie it is difficult to follow and understand your explanation. I changed the code as you suggested. However, I still get these error messages. You described something of two problems. Do I understand correctly that the changed code fixes the second problem but not the first?
x1 = ta.crossover(blueMACD, orgMACD) and barstate.isconfirme
x2 = ta.crossunder(blueMACD, orgMACD) and barstate.isconfirmed
plot((x1 > 0) and x1 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')
plot((x2 < 0) and x2 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')
EDIT: Where do I get the value where the lines cross to get a float value? I understood that a numeric value is not possible with a bool. I only want see the red dots, if they are above 0 and the green dots if they are below 0.
Upvotes: 0
Reputation: 21342
You have two issues here.
ta.crossover()
and ta.crossunder()
returns bool
. And you cannot compare bool
with float
as you do here.
if x1 > 0
if x2 < 0
Your second problem is, you cannot use the plot()
in local scope.
What you can do is, apply your condition directly to the series
parameter of the plot()
.
After you fix your first problem, you cna move that condition to the series
parameter of the plot()
(if necessary).
Then it would be:
plot((x1 > 0) and x1 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')
plot((x2 < 0) and x2 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')
Upvotes: 0