Can this logic work or how can i make this work in pine script is it possible or not

Viewed 56

What I want to do is just a break out retrace and enter. Is this possible in pine script or do I need to go for python?

breakout = close > plotHigh2[1] 
retrace = low < plotLow2[1]
entry = crossover(k,d)
var BULL = 0
if breakout
    BULL := 1

if BULL == 1 and retrace
    BULL := 2
    
if BULL == 2 
    plotshape(entry, location = location.belowbar) and BULL := 0
1 Answers
k = ta.sma(close, 10)
d = ta.sma(close, 20)
breakout = close > ta.highest(2)[1] 
retrace  = low < ta.lowest(2)[1]
entry    = ta.crossover(k,d)

var BULL = 0
if breakout       
    BULL := 1

if BULL == 1 and retrace
    BULL := 2
    
plotshape(BULL==2 and entry, location = location.belowbar)
if entry
    BULL := 0
Related