I want to write a simple condition for pine script that if the price hits the plus sign the background color will be green like the following picture. but I wrote it and it wasn't what I expected it makes background only for two candles and I want it for all of the next candles. How can I do that? Thank you This is the picture
//@version=4
study(title="My Indicator", overlay=true)
// Entry Point
entryPointLong = highest(high, 100)
entryPointShort = lowest(low, 100)
// Entry Point Condition
entryPointLongCond = close >= entryPointLong ? color.green : na
entryPointShortCond = close <= entryPointShort ? color.red : na
// Plot
plot(entryPointLong, title="Entry Long", style=plot.style_cross, linewidth=5, show_last=1, color=color.green)
plot(entryPointShort, title="Entry Short", style=plot.style_cross, linewidth=5, show_last=1, color=color.red)
// Background Color
bgcolor(entryPointLongCond, transp=70)
bgcolor(entryPointShortCond, transp=70)
Updated Code:
//@version=4
study(title="My Indicator", overlay=true)
// Entry Point
entryPointLong = highest(high, 100)
entryPointShort = lowest(low, 100)
// Stop Loss
stopLossLongInput = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=3) * 0.01
stopLossLong = entryPointLong * (1 - stopLossLongInput)
// Entry Point Condition
entryPointLongTrue = close >= entryPointLong
if entryPointLongTrue
entryPointLong := stopLossLong
color.green
entryPointLongCond = close >= entryPointLong ? color.green : na
entryPointShortCond = close <= entryPointShort ? color.red : na
// Plot
plot(entryPointLong, title="Entry Long", style=plot.style_cross, linewidth=5, show_last=1, color=color.green)
plot(entryPointShort, title="Entry Short", style=plot.style_cross, linewidth=5, show_last=1, color=color.red)
plot(stopLossLong, title="Entry Short", style=plot.style_cross, linewidth=5, show_last=1, color=color.red)
// Background Color
bgcolor(entryPointLongCond, transp=70)
bgcolor(entryPointShortCond, transp=70)
question from:
https://stackoverflow.com/questions/65868860/writing-a-simple-condition-for-pine-script 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…