There are some common patterns in MT4 programming and learning to use those effectively can make writing indicators and experts much easier.
In this short introduction I will show you how to create a function to loop through your open trades, use that loop to apply a trailing stop, and use all of that to create a complete working expert advisor.
This is a basic introduction and if you are serious about programming for MT4 then there are a number of improvements we can make but this will be a good starting point.
Please leave comments if you would like a follow up article to answer questions or to go into possible improvements or similar topics.
https://github.com/OrchardForexTutorials/200127_looping_through_trades_-trailing_stop-_part_1