Search code examples
pine-scriptpine-script-v5tradingpine-script-v4

I need to FIX THIS strategy in Pinescript please


Problem n.2Look at the pics!

high20= ta.highest(high, 20)[1] //easy line for breakout

short= close[1] and close[2] and close[3] and close[4] <= high20 and close >= high20//rules

plot(high20)
plotshape(short, shape.cross, color=color.orange)

QUESTION:

  1. How can I tell this strategy to only make an orange cross the first time the breakout occurs and not continue to make x every time the price closes above the high20 (Fixed by @Gu5tavo71)

  2. Look at the pics, I need a cross for each passed high. But at least four trading sessions must have passed between the present high and the previous one. This line doesn't work

short= close1 and close[2] and close[3] and close[4] <= high20 and close >= high20

thank you!


Solution

  • Try when condition "short", and previously not condition "short"

    something like that:

    plotshape(short and not short[1], shape.cross, color=color.orange)