PrinceZee
PrinceZee

Reputation: 1598

How is evaluated a series of data when passed after ?:

I'm new to pinescript and I try to understand how things works, I'm struggling to fully understand iff statement (?:) and how its evaluated series of data when they are passed after ?: for example.

higher_than = high > close
x = higher_than ? 1 : 0
b = x > 0 ? higher[2]: na

x is evaluated as for each value that is true in higher_than is replaced with 1, if a value is false it's replaced with 0. but how about the b statement? is does this work?

for each value in x that is superior to zero, replace it with higher value at the same index ?

Upvotes: 0

Views: 68

Answers (1)

PineCoders-LucF
PineCoders-LucF

Reputation: 8789

This shows you how to debug your script so that you can inspect all your calcs' values for each bar. Using the Data Window to debug is very useful. By inspecting the values in there, you should be able to answer your own questions. If you can't, just say so.

//@version=4
study("Debugging", "", true)
higher_than = high > close
x = higher_than ? 1 : 0
b = x > 0 ? high[2]: na
// This is a boolean so we plot a dot when it's true.
plotchar(higher_than, "higher_than", "•", location.top)
// This is a 0/1 value so we can't plot it on the chart because it will ruin the scale, so we plot it in the Data Window.
plotchar(x, "x", "", location.top)
// This value fits in the chart's price scale, so we can plot it directly on the chart. This plots the high from 2 bars ago.
plot(high[2], "high[2]")
// This also fits on the chart, but we use a different color and make the plot wider 
// and more transparent so the previous plot in the default blue can show through.
plot(b, "b", color.orange, 5, transp = 60)

enter image description here

Upvotes: 1

Related Questions