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

Examine condition of line(s) - touched/untouched


I need to examine the condition of a line (touched, untouched, traded) to conditionally style them.

I am good with "traded" condition (candle closes above/below line) but got no idea how to identify the "touched/untouched" condition. (e.g. just a wick into that line)

Someone please got a pointer?


Solution

  • You should look at the high and low values to see if a line is touched.

    For example, say the line is at 120, high price is 130 and close price is 110.

    By looking at those values, you can see that the price pushed through the line and pulled back below it. So, the line was touched.

    To check if the line is untouched, simply check if high < 120.

    Reverse the process for a line below the the price.