Rafael Wörner
Rafael Wörner

Reputation: 319

Pinescript can't handle division comparisons?

the following script should produce labels on top and bottom of the same bars. But mySeries1 puts under every bar a label. Can't pinescript handle this or am I doing something wrong?

//@version=4
study(title = "Division?", overlay=true)

labelPosLow = low - (atr(30) * 0.6)
labelPosHigh = high + (atr(30) * 0.6)

totalLength = high - low

mySeries1 = close - low >= 1/2 * totalLength 
if mySeries1
    label.new(bar_index, labelPosLow, text="A", style=label.style_label_up, color = color.blue, textcolor=color.white)
    
mySeries2 = close - low >= 0.5 * totalLength 
if mySeries2
    label.new(bar_index, labelPosHigh, text="B", style=label.style_label_down, color = color.green, textcolor=color.white)

Pinescript chart

Upvotes: 0

Views: 211

Answers (1)

SafetyHammer
SafetyHammer

Reputation: 411

Not sure what you trying to do or if you know that 1/2 is not equal to 0.5 in pine script. Change 1/2 to 1.0/2.0, this may work

Upvotes: 2

Related Questions