You could make a nazr (vow) that if you commit the sin then you have to do such and such for example fasting 3 days or give a certain amount of charity. Something difficult for you. This would defer you because when you want to commit the sin you will think of the things you have vowed to do if you make that sin.
The best way to avoid these kind of sins is marriage, be it temporary or permanent as the sheikh told you. Talk to your parents to find a suitable partner for marriage and tell them you don't want to fall in sin.
In the Holy Quran, Allah tells us that if however it is not possible for.you which is of course after you've tried your best, then you have to remain chaste, and Allah will surely reward you and show you a way out of your predicament inshAllah.
Try your best to avoid the circumstances and habits that give rise to those thoughts. spend more time in places where these thoughts are less likely to arise, such as with your parents, siblings or good freinds, or even your local mosque. Busy yourself whenever the thought of sin arises. Seek refuge in Allah from shaitan. Know that if you hate the sin and are trying all your best not to indulge, then Allah loves you as per traditions of Masomeen a.s
Second you should use your mental will power to keep those thoughts out of your mind by keeping away from any kind of bad scenes around you specially the media. You have to vow yourself to Allah if its become a habit for you.
This can help you a great deal through
Fasting, regular prayer and lowering libido-increasing food such as all nuts, chocolate, spices, bananas etc you can research on the foods that have a hot effect in your temperament and avoid taking them.
Regular exercise and swimming also helps exhaust your excess libido.
Its also very good to bath part of the body suffering from sin with cold water.
InshAllah you will soon overcome these sins by practicing all this with great hope and diligence. If you take it lightly, you will only cause harm to yourself and your future generation which inshAllah will be pure if you start now with the help of the All Merciful.