简体   繁体   中英

Pinescript - background color "repaints" when the candle closes

I´m kinda new to scripting, So the thing is I set this tiny script to color the background when the candle crosses over the price of the laste candle, which works fine when that happens.

But if the price retracts and closes lower of the previous candle the coloring dissapears. How can I leave the background painted, even if the price retracts?

背景重绘

//@version=5
strategy(title="Crossup", calc_on_every_tick=true, overlay=true)

closeHigher = (close > high[1])
bgcolor(color=closeHigher ? color.rgb(6, 46, 8, 56) : na)

In that case, you don't want to use close . Instead, you should use high . Once current bar's high is higher than the previous bar's high , there is no way for that condition to become false . high will not go any lower, it can only go even higher:)

//@version=5
strategy(title="Crossup", calc_on_every_tick=true, overlay=true)

closeHigher = (high> high[1])
bgcolor(color=closeHigher ? color.rgb(6, 46, 8, 56) : na)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM