The ideals are:
- Draw red area on the screen when K is over 80 - no new red area will be drawing until K is reached under 20 before that
- Draw green area on the screen when K is under 20 - no new green area will be drawing until K is reached under 80 before that
Currently I'm trying to limit the draw of the signal on the screen by changing the value of variables. But it does not seem to work as expected. Please help me identify the wrong on the logic and correct it here is the code
lookback = input(title = 'Period', defval = 13)
highest = ta.highest(high, lookback)
lowest = ta.lowest(low, lookback)
stochastic_K = ((close - lowest) / (highest - lowest)) * 100
upbefore = false
downbefore = false
// Im trying to change the variable value in there:
if stochastic_K > 80
upbefore := true
downbefore := false
if stochastic_K < 20
upbefore := false
downbefore := true
//color change
readyforbuy = downbefore == true
readyforsell = upbefore == true
backgroundcolor = readyforbuy? color.rgb(33, 149, 243, 63): readyforsell? color.rgb(255, 82, 82, 54): na
// Draw area
bgcolor(color = backgroundcolor)
As you can see from the image above, although the Stochastic is not going under 20 yet, but the green area still being draw. And I want to prevent that to improve my signal.