Comment on Managing your Script
The thing is that your buying price as such cannot be captured in an algo.
What you can have thought is that whatever is your buying condition, you can have a selling condition which is an increment of your buying condition