You can achieve your goal by writing a custom indicator by means of our Pine Script language.
The following materials might be helpful:
Pine Script Tutorial
Pine Script Reference
You can also ask a question in the Stack Overflow Pine Community, or contact the most active study developers of our community in the Pine Script TV chat.