Take profit and Stop loss on the nearest PIVOT POINT

 

Hi guys

I am programming ea and now i have problem with settings stop loss and take profit. I want set them on the nearest pivot point from candle of which buy or sell was created.

Thank you for your advices.

Reason: