Flag for Code taking profit

 
hello,

Is there a way we can find out if the code took profit or sell at a loss? Is there a function that tells this? I need to find out because my code needs it because i set buysignal to true once a criteria is met. But I cannot set it to false if it takes profit because i dont have a way to find out ..

thank you.
Reason: