Yuwaz
Yuwaz

Reputation: 413

How to keep the current state in a PINE script?

I'm developing an indicator for opening and closing long positions with a PINE script.

The triangle means open and the cross means close.

The condition to be judged as close may occur multiple times, and the closed mark is displayed even if it is not open.

enter image description here

Is there a way to keep the "open" state?

My script:

//@version=4
study(title="My Script", shorttitle="My Script", overlay=true, resolution="")

cond_long_open = // same condition
cond_long_close = // same condition
plotshape(cond_long_open , style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(cond_long_close, style=shape.xcross, location=location.abovebar, color=color.green)

Upvotes: 1

Views: 1148

Answers (1)

bajaco
bajaco

Reputation: 980

Use the var keyword to initialize variables only once.

var bool cond_long_open = false
var bool cond_long_close = false

if long
    cond_long_open := true

Something like that.

Upvotes: 4

Related Questions