Stop loss change to pending order value

 

Hi guys,

I would like to create a function that would change my stop loss value from preset one to a next pending order level (if the distance is smaller than preset stop loss). Basically I would like to make the pending order close the opposite open one if the distance between them is smaller than the preset stop loss.

I would like to mention that I am pretty fresh in the community as well as in the coding stuff so please bear with us...

Waiting for some code samples or locations where can I find some solutions.

Reason: